Using a list comprehension
line = '0,1,2,3,4,5,6,7,8,9,10'
lst = line.split(',')
one, four, ten = [lst[i] for i in [1,4,10]]
Answer from has2k1 on Stack OverflowHow to get specific values from an element of the list
How to access List elements in Python - Stack Overflow
How can I get a value at any position of a list
[Python] Elementtree - how to select certain attribute from one selected root.
Videos
Using a list comprehension
line = '0,1,2,3,4,5,6,7,8,9,10'
lst = line.split(',')
one, four, ten = [lst[i] for i in [1,4,10]]
I think you are looking for operator.itemgetter:
import operator
line=','.join(map(str,range(11)))
print(line)
# 0,1,2,3,4,5,6,7,8,9,10
alist=line.split(',')
print(alist)
# ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
one,four,ten=operator.itemgetter(1,4,10)(alist)
print(one,four,ten)
# ('1', '4', '10')
Hello everyone!
I have a document in Word that I've already parsed.
Here's how headings of that document look like in the list:
['Client Acceptance Screening Report on LTD Western Stream','Analysis of actual or alleged integrity issues','International blacklists, sanctions or other geopolitical concerns','Politically Exposed Persons (PEP)','Corporate details']
How can I get everything from the first element of the list after the word 'on'. I need to get the name of the legal entity which is LTD 'Western Stream'.
I tried this:
scanning = False
for i[0] in heading:
if i == 'o' and i+1 == 'n':
scanning = True
continue
if scanning == True:
print(i)But it doesn't work.
I also tried this, but it doesn't work either:
scanning = False
for i[0] in heading:
i[0] = q
if q == 'o' and q == 'n':
scanning = True
continue
if scanning == True:
print(q)I would be very grateful for the help.
I'd start by not calling it list, since that's the name of the constructor for Python's built in list type.
But once you've renamed it to cities or something, you'd do:
print(cities[0][0], cities[1][0])
print(cities[0][1], cities[1][1])
It's simple
y = [['vegas','London'],['US','UK']]
for x in y:
for a in x:
print(a)