Skip to content

Commit 337cbba

Browse files
authored
Add comment and improve variable name in roundrobin() (#4486)
1 parent bc9b6e2 commit 337cbba

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Doc/library/itertools.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,15 +753,16 @@ which incur interpreter overhead.
753753
def roundrobin(*iterables):
754754
"roundrobin('ABC', 'D', 'EF') --> A D E B F C"
755755
# Recipe credited to George Sakkis
756-
pending = len(iterables)
756+
num_active = len(iterables)
757757
nexts = cycle(iter(it).__next__ for it in iterables)
758-
while pending:
758+
while num_active:
759759
try:
760760
for next in nexts:
761761
yield next()
762762
except StopIteration:
763-
pending -= 1
764-
nexts = cycle(islice(nexts, pending))
763+
# Remove the iterator we just exhausted from the cycle.
764+
num_active -= 1
765+
nexts = cycle(islice(nexts, num_active))
765766
766767
def partition(pred, iterable):
767768
'Use a predicate to partition entries into false entries and true entries'

0 commit comments

Comments
 (0)