]> granicus.if.org Git - python/commitdiff
Add comment and improve variable name in roundrobin() (GH-4486) (#4487)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 21 Nov 2017 08:29:34 +0000 (00:29 -0800)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>
Tue, 21 Nov 2017 08:29:34 +0000 (00:29 -0800)
(cherry picked from commit 337cbbace0a43f50fcd33ea4d3b7cb30733237db)

Doc/library/itertools.rst

index 86a590bb67c17ee35e5aefe71f49e9f5299904d2..594af39f60f1f51a894b0c2aae022794c22bdca1 100644 (file)
@@ -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'