Skip to content Skip to sidebar Skip to footer

How To Split Tuple With Parentheses In Python?

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. I have to split the tuple su

Solution 1:

you can get the tuple into individual variables in the for statement as following:

for u,v in link_list:
     print u,v

Solution 2:

Simple:

forlinkin link_list:
    u, v = linkprint u, v

It's called sequence unpacking.

Solution 3:

If you have a tuple (x,y), and you wish to destructure it to two variables, the syntax is simply:

u,v = (x,y)

Post a Comment for "How To Split Tuple With Parentheses In Python?"