Reputation: 35
Let us consider
x = ['1', '2', '3', '4', '5'] y = ['a', 'b', 'c', 'd', 'e']
How do I get the required output z?
z
z = [('1', 'a') , ('b', '2') , ('c', '3') , ('d', '4') , ('e', '5')]
Upvotes: 1
Views: 158
Reputation: 65791
It's called zip:
z = zip(x, y)
Upvotes: 3
Reputation: 287785
You're looking for zip:
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