Commit 2f08df36 authored by Raymond Hettinger's avatar Raymond Hettinger

Issue #10029: Fix sample code in the docs for zip().

parent 5b0e9e84
......@@ -1237,9 +1237,16 @@ are always available. They are listed here in alphabetical order.
def zip(*iterables):
# zip('ABCD', 'xy') --> Ax By
iterables = map(iter, iterables)
sentinel = object()
iterables = [iter(it) for it in iterables]
while iterables:
yield tuple(map(next, iterables))
result = []
for it in iterables:
elem = next(it, sentinel)
if elem is sentinel:
return
result.append(elem)
yield tuple(result)
The left-to-right evaluation order of the iterables is guaranteed. This
makes possible an idiom for clustering a data series into n-length groups
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment