我有一个字典,其中包含每个键的两级嵌套列表,如下所示:
OrderedDict([(0,[['a','b','c','d'],['e','f','g','h']]), (1,[['i','j','k','l'],['m','n','o','p']])])
我想将每个嵌套列表作为列写入 csv:
a,b,c,d e,f,g,h
i,j,k,l m,n,o,p
我从当前代码中得到的输出是:
['a','b','c','d'] ['e','f','g','h']
['i','j','k','l'] ['m','n','o','p']
列是正确的,但我想删除括号 [] 和引号 ''
a,b,c,d e,f,g,h
i,j,k,l m,n,o,p
代码:
with open('test.csv', 'w', newline='') as csv_file:
writer = csv.writer(csv_file, quotechar='"', quoting=csv.QUOTE_ALL)
for record in my_dict.values():
writer.writerow(record)
任何帮助,将不胜感激!