如何将以下词典打印到 csv 文件中?
maxDict = {'test1': ('alpha', 2), 'test2': ('gamma', 2)}
因此,输出 CSV 如下所示:
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())
关于Python:如何将元组值字典写入 csv 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5530619/