Extracting data from Excel sheet
for value in quoted.findall(str(row[2])):
i.append(value.replace('"', '').strip())
print i
Then i get a set of lists as below
['M', 'N', 'O']
['P', 'Q', 'R']
['S', 'T', 'U']
['W', 'X', 'Y']
how do i make this set of list in another list, i am expecting output as
[ ['M', 'N', 'O'], ['P', 'Q', 'R'], ['S', 'T', 'U'], ['W', 'X', 'Y'] ]
if i want to access this list, i simply use listOfList[2]
and i should get
['S', 'T', 'U']
thanks in advance.
与Nirk的答案相同,但使用列表推导:
j = [[value.replace('"', '').strip() for value in quoted.findall(str(row[2]))] for row in ...]
Instead of printing. just append the entire list to another list:
j=[];
for row in ... :
i = []
for value in quoted.findall(str(row[2])):
i.append(value.replace('"', '').strip())
j.append(i)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.