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?
for l in Python_List:, then the next line reduces tof.write('%s,%s\n' % tuple(l)). Anyway you should usecsv.writer.