如何用一个键将多个值的字典写入csv文件
问题描述:
我有一个以下形式的字典:
I have a dictionary of the following form
>>> {'1' : [V3210 , 234567 ,1235675 , 23], '2' : [v3214 , 5678 ,65879 ,89} , ...}
如何将此字典写入csv文件
how to write this dictionary to a csv file??
感谢
答
使用内置 csv 模块。这是假设您要在键,值1,值2,...
格式。
Use the builtin csv module. This is assuming you want it in a key,value1,value2,...
format.
import csv
with open('filename', 'w') as f:
c = csv.writer(f)
for key, value in d.items():
c.writerow([key] + value)