First page Back Continue Last page Overview Graphics

zip

zip creates an iterator that aggregates elements from each of the iterables of the arguments.

Returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.

>>> list(zip((3,5,6,7), (12,14,16,19), (21,25,27,28) ))

[(3, 12, 21), (5, 14, 25), (6, 16, 27), (7, 19, 28)]

The iterator stops when the shortest input iterable is exhausted:

>>> list(zip((3,5,6,7), (12,14,16,19), (21,25,27) ))

[(3, 12, 21), (5, 14, 25), (6, 16, 27)]

With a single iterable argument, it returns an iterator of 1-tuples:

>>> list(zip((3,5,6,7,12)))

[(3,), (5,), (6,), (7,), (12,)]