所以我有一个这种格式的列表:
[(532, 'working'), (417, 'texting')]
我想以以下格式将其写入文本文件中:
532 working
417 texting
答案 0 :(得分:0)
以下实现按预期工作:
input = [(532, 'working'), (417, 'texting')]
with open("output.txt", "w") as opened_file:
for element in input:
opened_file.write("%s %s\n" % (element[0], element[1]))
输出:
>>>cat output.txt
532 working
417 texting