1

I am facing a problem to convert from List to tuple. For example i have lists like this

['1', '9']
['2']
['3']
['4']

I want output like this [(1,9),(2),(3),(4)] Kindly help me. I am not getting any way.

1 Answer 1

2

If you have a list 'l' then you can call the builtin function 'tuple' on it to convert to a tuple

l = [1,2]
tup = tuple(l)
print tup # (1,2)

if you have a list of list l = [['1', '9'], ['2'], ['3'], ['4']]

you can do :

l = [['1', '9'], ['2'], ['3'], ['4']]
tups = map(lambda x: tuple(x), l)
print tups #  [(1,9),(2),(3),(4)] 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @gypsy. I am new to Python , so could not figure out it.

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.