gpt4 book ai didi

python - 如何在 python 中拆分元组

转载 作者:行者123 更新时间:2023-12-01 22:24:08 25 4
gpt4 key购买 nike

如何从字典中拆分元组

dic = {('K30', 'K56'): 1}

在文本文件中获取此输出:

K30    K56    1

我试过的是

for k,v in dic.items():
a,b = k.split(',')
print >>f, a+'\t',b+'\t',v
f.close()

但是我得到了错误:

AttributeError: 'tuple' object has no attribute 'split'

最佳答案

你不需要拆分你可以简单地说

 a,b = k

关于python - 如何在 python 中拆分元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37427207/

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