gpt4 book ai didi

python - 在 Python 中将元组列表写入文本文件

转载 作者:太空狗 更新时间:2023-10-30 00:23:40 28 4
gpt4 key购买 nike

我有一个元组列表,格式如下:

("some string", "string symbol", some number)

例如,("Apples", "=", 10)。我需要将它们写入输出文件,如下所示:

Apples = 10

我在使用 write 方法时遇到了问题。怎么做到的?

最佳答案

您可以使用:

for t in some_list:
f.write(' '.join(str(s) for s in t) + '\n')

f 是您的文件

关于python - 在 Python 中将元组列表写入文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8366276/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com