0

At the moment I am scraping data from the web and want to output it into CSV. Everything is working fine but as soon as I append more than one list in the iteration the list has the wrong format.

I start with sth like this:

list = [a, b, c]
list_two = [d, e, f]
list_three = [g, h, i]

first iteration:

list = [list, list_two]
# list = [[a, b, c], [d, e, f]]

second iteration:

list = [list, list_three]

I get:

# list = [[[a, b, c], [d, e, f]], [g, h, i]]

I want to have:

# list = [[a, b, c], [d, e, f], [g, h, i]]

Please help me! I guess it is a easy thing but I do not get it. And I actually struggle to find information on how to append lists.

4

2 回答 2

2

只需使用 + 连接两个列表:

list = [ list, list_two ]
list += [ list_three ]

您还可以使用 append :

list = [ list ]
list.append( list_two )
list.append( list_three )
于 2013-05-25T11:13:57.307 回答
1

您可以创建一个帮助列表并使用附加:

例如

helperList = []
list = ['a', 'b', 'c']
list_two = ['d', 'e', 'f']
list_three = ['g', 'h', 'i']

helperList.append(list)
helperList.append(list_two)
helperList.append(list3_three)

#helperList >>> [['a', 'b', 'c'], ['d', 'e', 'g'], ['g', 'h', 'i']]
于 2013-05-25T22:29:10.577 回答