CKTIS / Python
zip()
Groups parallel items from multiple iterables into tuples.
Version: Python 3.14; repository image, production runtime not attested
Syntax
zip(*iterables, strict=False)Groups parallel items from multiple iterables into tuples.
The default truncates at the shortest input; strict mode raises ValueError when lengths differ.
The first values a and 2 form one tuple. In default mode the shorter input then ends and b gets no partner. Strict mode yields the same first tuple and raises ValueError only when a later pull discovers the mismatch. With zero input iterables the result is empty.
it = zip("ab", [2], strict=True)
assert next(it) == ("a", 2)
try:
next(it)
except ValueError:
pass
else:
raise AssertionError
Examples
print(list(zip("ab", [2])))
try:
list(zip("ab", [2], strict=True))
except ValueError as error:
print(type(error).__name__)
Result
[('a', 2)]
ValueErrorThe first values a and 2 form one tuple. In default mode the shorter input then ends and b gets no partner. Strict mode yields the same first tuple and raises ValueError only when a later pull discovers the mismatch. With zero input iterables the result is empty.