python - Writing a dictionary to a csv file with one line for every 'key: value' - Stack Overflow

PHOTO EMBED

Mon Apr 26 2021 15:51:51 GMT+0000 (Coordinated Universal Time)

Saved by @chenyangsu #python

with open('dict.csv', 'w') as csv_file:  
    writer = csv.writer(csv_file)
    for key, value in mydict.items():
       writer.writerow([key, value])
content_copyCOPY

https://stackoverflow.com/questions/8685809/writing-a-dictionary-to-a-csv-file-with-one-line-for-every-key-value