How do I print the following dictionary into a csv file?
maxDict = {'test1': ('alpha', 2), 'test2': ('gamma', 2)}
So, that the output CSV looks as follows:
test1, alpha, 2
test2, gamma, 2
import csv
with open("data.csv", "wb") as f:
csv.writer(f).writerows((k,) + v for k, v in maxDict.iteritems())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With