Skip to content Skip to sidebar Skip to footer

Append Lists For Csv Output In Python

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 th

Solution 1:

Just use + to concatenate two lists :

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

You could also use append :

list = [ list ]
list.append( list_two )
list.append( list_three )

Solution 2:

You can create a helper list and use append:

For example

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']]

Post a Comment for "Append Lists For Csv Output In Python"