mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Add comment and improve variable name in roundrobin() (#4486)
This commit is contained in:
committed by
GitHub
parent
bc9b6e29cb
commit
337cbbace0
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user