Reputation: 8297
May I know the python built-in function to do the following? That is, combine 2 lists into 1 list such that the elements of each list is used to form a tuple element in the new list. Thank you.
>>> a = ['1','2','3']
>>> b = ['x','y','z']
>>> c = []
>>> for i, val in enumerate(a):
c.append( (i, b[i]) )
>>> c
[(0, 'x'), (1, 'y'), (2, 'z')]
>>>
Upvotes: 2
Views: 157
Reputation: 71610
It is zip
:
>>> list(zip(a,b))
[('1', 'x'), ('2', 'y'), ('3', 'z')]
Upvotes: 5