我有一个包含以下元素的列表:
listes = [["a","b"],["c","d"],["e","f"]]
我习惯用这段代码编写我的csv:
with open("result.csv", "wb") as f:
writer = csv.writer(f, delimiter=';')
writer.writerows(listes)
结果:
a;b
c;d
e;f
但 我想:
a;c;d
b;e;f
由于
答案 0 :(得分:0)
转置您的列表并写入文件
with open("result.csv", "wb") as f:
writer = csv.writer(f, delimiter=';')
writer.writerows(zip(*listes))