Next / Previous / Contents / TCC Help System / NM Tech homepage

13.42. zip(): Combine multiple sequences

Given two or more sequences S0, S1, S2, ... with the same number of elements, you can combine them to produce a list of tuples (v0, v1, ...) such that each v0 comes from S0, each v1 comes from S1, and so on.

The action of this function is probably best explained by examples:

>>> L1=[1,2,3,4]
>>> L2=['a', 'b', 'c', 'd']
>>> zip(L1, L2)
[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')]
>>> L3=[10.0, 20.0, 30.0, 40.0]
>>> zip(L1, L2, L3)
[(1, 'a', 10.0), (2, 'b', 20.0), (3, 'c', 30.0), (4, 'd', 40.0)]