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
| Name | Description |
|---|---|
| *iterables | Two or more iterables whose items should be grouped. |
| strict | Use 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)raisesValueErrorif iterables are not of equal length.