how to write a dictionary with one key multiple values to a csv file

后端 未结 3 1341
南笙
南笙 2021-01-27 07:13

I have a dictionary of the following form

>>> {\'1\' : [V3210 , 234567 ,1235675 , 23], \'2\' : [v3214 , 5678 ,65879 ,89} , ...}

how to

3条回答
  •  一向
    一向 (楼主)
    2021-01-27 08:07

    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)
    

提交回复
热议问题