[Python-checkins] Add comment and improve variable name in roundrobin() (#4486)

Raymond Hettinger webhook-mailer at python.org
Tue Nov 21 03:23:42 EST 2017


https://github.com/python/cpython/commit/337cbbace0a43f50fcd33ea4d3b7cb30733237db
commit: 337cbbace0a43f50fcd33ea4d3b7cb30733237db
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2017-11-21T00:23:34-08:00
summary:

Add comment and improve variable name in roundrobin() (#4486)

files:
M Doc/library/itertools.rst

diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index fa6c340bb7b..a91894059d0 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'



More information about the Python-checkins mailing list