How to map two tuples into a list of tuple in python?

Question:

I want to map two tuples into a new list in python. One To One relation between that two tuples and then convert that into list.

tup_1 = (1, 2, 3)
tup_2 = (4, 5, 6)
x = map(tup_1, tup_2)
>>> x
[(1, 4), (2, 5), (3, 6)]
Asked By: TheWorrier

||

Answers:

I want to map two tuples into a new list in python.

It is very easy in python, just use zip function of python, that will give you an iterative object. Convert that object into list using list function of python.

tup_1 = (1, 2, 3)
tup_2 = (4, 5, 6)
x = list(zip(tup_1, tup_2))
>>> x
[(1, 4), (2, 5), (3, 6)]
Answered By: Harsh Narwariya
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.