File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1220,11 +1220,18 @@ are always available. They are listed here in alphabetical order.
12201220 iterable argument, it returns an iterator of 1-tuples. With no arguments,
12211221 it returns an empty iterator. Equivalent to::
12221222
1223- def zip(*iterables):
1224- # zip('ABCD', 'xy') --> Ax By
1225- iterables = map(iter, iterables)
1226- while iterables:
1227- yield tuple(map(next, iterables))
1223+ def zip(*iterables):
1224+ # zip('ABCD', 'xy') --> Ax By
1225+ sentinel = object()
1226+ iterables = [iter(it) for it in iterables]
1227+ while iterables:
1228+ result = []
1229+ for it in iterables:
1230+ elem = next(it, sentinel)
1231+ if elem is sentinel:
1232+ return
1233+ result.append(elem)
1234+ yield tuple(result)
12281235
12291236 The left-to-right evaluation order of the iterables is guaranteed. This
12301237 makes possible an idiom for clustering a data series into n-length groups
You can’t perform that action at this time.
0 commit comments