0

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.

4

2 回答 2

3

与 Nirk 的回答相同,但使用列表推导:

j = [[value.replace('"', '').strip() for value in quoted.findall(str(row[2]))] for row in ...]
于 2013-10-21T09:20:41.940 回答
1

而不是打印。只需将整个列表附加到另一个列表:

j=[];
for row in ... :
    i = []
    for value in quoted.findall(str(row[2])):
        i.append(value.replace('"', '').strip())

    j.append(i)
于 2013-10-21T05:47:06.310 回答