summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-11-21 08:29:34 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2017-11-21 08:29:34 (GMT)
commit32b003aca3e9d670367bd62cbf355ee61fa6b308 (patch)
tree26c82469bbeac8e121bd655d002aa1aec39f4462
parent60a376cf0023d1070329d0e861a5596637ff3275 (diff)
downloadcpython-32b003aca3e9d670367bd62cbf355ee61fa6b308.zip
cpython-32b003aca3e9d670367bd62cbf355ee61fa6b308.tar.gz
cpython-32b003aca3e9d670367bd62cbf355ee61fa6b308.tar.bz2
Add comment and improve variable name in roundrobin() (GH-4486) (#4487)
(cherry picked from commit 337cbbace0a43f50fcd33ea4d3b7cb30733237db)
-rw-r--r--Doc/library/itertools.rst9
1 files changed, 5 insertions, 4 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 86a590b..594af39 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'