Python:如何将字典中的值写入文件?
有个字典{'1000':{'1':['a','b','c','d'],'2'::['e','b','c','a'],},'2000':{'1':['c','d','c',...
有个字典{'1000':{'1':['a','b','c','d'],'2'::['e','b','c','a'],},'2000':{'1':['c','d','c','d'],'2':['a','a','c','d'],}}
我想将list中的数据写入csv文件。以'1000'和'2000'分开,然后再在1000中分出'1'和'2'来。再在2000中分出'1'和'2'来。 展开
我想将list中的数据写入csv文件。以'1000'和'2000'分开,然后再在1000中分出'1'和'2'来。再在2000中分出'1'和'2'来。 展开
展开全部
yourDict={'1000':{'1':['a','b','c','d'],'2':['e','b','c','a']},'2000':{'1':['c','d','c','d'],'2':['a','a','c','d']}}
out=open('out.xls','w')
for key in yourDict:
out.write(key)
for key2 in yourDict[key]:
out.write('\t')
out.write(key2+'\t')
out.write('\t'.join(yourDict[key][key2] ))
out.write('\n')
最后xls转存为csv即可
out=open('out.xls','w')
for key in yourDict:
out.write(key)
for key2 in yourDict[key]:
out.write('\t')
out.write(key2+'\t')
out.write('\t'.join(yourDict[key][key2] ))
out.write('\n')
最后xls转存为csv即可
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询