Skip to content
Built-in Functions

zip()

Pair items from two or more iterables.

zip(*iterables, strict=False)

zip() iterates over several iterables in parallel, producing tuples with an item from each one.

Stops as soon as the shortest input iterable is exhausted (unless strict=True is passed in Python 3.10+).

Parameters

NameDescription
*iterablesTwo or more iterables whose items should be grouped.
strictUse True to raise an error when lengths do not match.

Returns

A zip iterator of tuples.

Try it

Run it and change it
names = ["Ada", "Lin"]
scores = [9, 8]
print(list(zip(names, scores)))

Worth knowing

  • Strict mode: zip(a, b, strict=True) raises ValueError if iterables are not of equal length.

Related entries