I have a list of strings which I would like to write to a csv file. The list list_results
looks like
['False, 60, 40 ', 'True, 70, 30, ']
So, I would try something like this:
with open('example1.csv', 'w') as result:
writer = csv.writer(result, delimiter=",")
writer.writerow( ('Correct?', 'Successes', 'Failures') )
writer.writerows(list_results)
Unfortunately, the data doesn't write into three columns. I find:
['Correct?', 'Successes', 'Failures']
['F', 'a', 'l', 's', 'e', ',', ' ', '6', '0', ',', ' ', '4', '0', ' ']
['T', 'r', 'u', 'e', ',', ' ', '7', '0', ',', ' ', '3', '0', ',', ' ']
How do I format this behavior appropriately to get
['Correct?', 'Successes', 'Failures']
['False', 60, 40]
['True', 70, 30]
Preferably in format %s %d %d
?
See Question&Answers more detail:
os