zip() Parallel iteration
Last updated: 2026-09-22
zip() Parallel iteration
zip(*iterables) combines iterables in parallel, stopping at the shortest (or raising if strict=True).
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | 3.10+ |
📝 Syntax
zip(*iterables, strict=False)
⚙️ Parameters
| iterables Required | Varargs: multiple iterables combined in parallel. |
|---|---|
| strict Optional | When True, require equal lengths (Python 3.10+).(Default:False) |
Returns:An iterator of tuples pairing same-index elements; stops at the shortest input.
💥 Raises
ValueError— Raised when strict=True and lengths differ.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
a 1
b 2
c 3
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat happens when zip() meets two sequences of unequal length?
ABy default it truncates at the shortest, discarding extra elements — e.g. zip('abc', '12') only yields ('a','1') and ('b','2'); to raise an explicit error use zip(a, b, strict=True) (Python 3.10+).
QWhat does zip(*lst) do?
AIt unpacks and transposes: zip(*[(1, 'a'), (2, 'b')]) gives (1, 2) and ('a', 'b'), turning 'rows' into 'columns' — commonly used for matrix transposition.
QWhat does zip() return?
AIt returns a lazy zip iterator; use list(zip(...)) to get a list, and calling it with no arguments returns an empty iterator.
QHow many lists can zip() iterate over at once?
AAny number: for a, b, c in zip(x, y, z): pulls values in parallel, the standard way to traverse several sequences at once.