如何在Python中用括号分割元组? [英] How to split tuple with parentheses in Python?
本文介绍了如何在Python中用括号分割元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像(u,v)
的内置元组.它们由Networkx生成,并在图形中显示链接.我从被称为link_list
的列表中列出.
I have built-in tuple which looks like (u,v)
. They are generated by Networkx and they show links in a graph. I make a list out of the called link_list
.
我必须拆分元组,以便结果为:u , v
I have to split the tuple such that the outcome would be: u , v
我尝试了divmod
,但是它没有给出正确的答案.
I tried divmod
but it doesn't give the right answer.
for link in link_list:
u,v = divmod(*link)
print u,v
推荐答案
简单:
for link in link_list:
u, v = link
print u, v
它称为序列解压缩.
这篇关于如何在Python中用括号分割元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文