Using zip()

Takes two lists as parameters and returns a list of tuples where the i-th tuple contains the i-th items from each sequence. This is best explained with an example.

>>> x = ['a','b','c']
>>> y = ['d','e','f']
>>> zipped = zip(x,y)
>>> zipped
[('a', 'd'), ('b', 'e'), ('c', 'f')]
>>>

Tags: