Karthik Reddi
Karthik Reddi

Reputation: 35

Lists and Tuples

Let us consider

x = ['1', '2', '3', '4', '5']
y = ['a', 'b', 'c', 'd', 'e']

How do I get the required output z?

z = [('1', 'a') , ('b', '2') , ('c', '3') , ('d', '4') , ('e', '5')]

Upvotes: 1

Views: 158

Answers (2)

Lev Levitsky
Lev Levitsky

Reputation: 65791

It's called zip:

z = zip(x, y)

Upvotes: 3

phihag
phihag

Reputation: 287785

You're looking for zip:

>>> x = ['1', '2', '3', '4', '5'] 
>>> y = ['a', 'b', 'c', 'd', 'e']
>>> z = zip(x, y)
>>> z
[('1', 'a'), ('2', 'b'), ('3', 'c'), ('4', 'd'), ('5', 'e')]

Upvotes: 8

Related Questions