1

I have a list of tuples like the following

list=[(1,2),(3,4),(5,6)]

now I need to add them to a new tuple tup=()

my resultant tuple should look like tup=((1,2),(3,4),(5,6))

I tried using the following code:

 for each in list:

    tup=tup,each

the result is

(((), (627, 2)), (627, 3))

Can someone help me solving this?

1
  • list is a built in function, use a different variable name. Commented Dec 19, 2014 at 11:39

1 Answer 1

6

You just need to convert with tuple function :

>>> my_list=[(1,2),(3,4),(5,6)]
>>> tuple(my_list)
((1, 2), (3, 4), (5, 6))

note : dont use the built-in functions name or python keywords as your structure and variables name!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.