Python Function Reference

zip

Iterate over several iterables in parallel, collecting their items into tuples.

Python 3.13
zip(*iterables, strict=False)
  • =default value
*iterables
The objects whose items are collected into tuples in order.
Iterable
strict
If True, raises ValueError when the lengths differ.
boolOptional

Return value

An iterator of tuples; by default it stops at the shortest iterable.

Examples

Pairs from two lists

Python 3.13
print(list(zip(['a', 'b'], [1, 2])))
[('a', 1), ('b', 2)]

Stopping at the shortest list

Python 3.13
print(list(zip([1, 2, 3], ['a', 'b'])))
[(1, 'a'), (2, 'b')]

Details

Without strict=True, the extra items of longer iterables are silently dropped, which makes it easy to lose data. To fill in missing values with a default, use itertools.zip_longest. zip(*pairs) splits a list of pairs back into separate tuples.

See also