I've a nested list like Python_List
below and I want to make a .csv
like below:
Python_List|-> .csv
[['2','4'],| 2,4
['6','7'],| 6,7
['5','9'],| 5,9
['4','7']]| 4,7
So far I'm using this code:
Python_List=[['2','4'], ['6','7'], ['5','9'], ['4','7']]
with open('test.csv','w') as f:
for i in range(0,len(Python_List)):
f.write('%s,%s\n' %(Python_List[i][0],Python_List[i][1]))
Are there any alternatives more efficient?
You can csv module and its
writer
method, like thisConsider using the writer method of the csv module.
It may not be more efficient but it will be easier to understand.
For Example