[英]how do i make list of list python
Extracting data from Excel sheet 从Excel工作表中提取数据
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 如果我要访问此列表,则只需使用listOfList[2]
,我应该得到
['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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.