diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2017-11-21 08:23:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-21 08:23:34 (GMT) |
commit | 337cbbace0a43f50fcd33ea4d3b7cb30733237db (patch) | |
tree | 338b425fddab577f880a1fc8f962492f642c3c49 /Doc | |
parent | bc9b6e29cb52f8da15613f9174af2f603131b56d (diff) | |
download | cpython-337cbbace0a43f50fcd33ea4d3b7cb30733237db.zip cpython-337cbbace0a43f50fcd33ea4d3b7cb30733237db.tar.gz cpython-337cbbace0a43f50fcd33ea4d3b7cb30733237db.tar.bz2 |
Add comment and improve variable name in roundrobin() (#4486)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/itertools.rst | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index fa6c340..a918940 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -753,15 +753,16 @@ which incur interpreter overhead. def roundrobin(*iterables): "roundrobin('ABC', 'D', 'EF') --> A D E B F C" # Recipe credited to George Sakkis - pending = len(iterables) + num_active = len(iterables) nexts = cycle(iter(it).__next__ for it in iterables) - while pending: + while num_active: try: for next in nexts: yield next() except StopIteration: - pending -= 1 - nexts = cycle(islice(nexts, pending)) + # Remove the iterator we just exhausted from the cycle. + num_active -= 1 + nexts = cycle(islice(nexts, num_active)) def partition(pred, iterable): 'Use a predicate to partition entries into false entries and true entries' |