Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
337cbbac
Commit
337cbbac
authored
Nov 21, 2017
by
Raymond Hettinger
Committed by
GitHub
Nov 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add comment and improve variable name in roundrobin() (#4486)
parent
bc9b6e29
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
4 deletions
+5
-4
Doc/library/itertools.rst
Doc/library/itertools.rst
+5
-4
No files found.
Doc/library/itertools.rst
View file @
337cbbac
...
@@ -753,15 +753,16 @@ which incur interpreter overhead.
...
@@ -753,15 +753,16 @@ which incur interpreter overhead.
def roundrobin(*iterables):
def roundrobin(*iterables):
"roundrobin('ABC', 'D', 'EF') --> A D E B F C"
"roundrobin('ABC', 'D', 'EF') --> A D E B F C"
# Recipe credited to George Sakkis
# Recipe credited to George Sakkis
pending
= len(iterables)
num_active
= len(iterables)
nexts = cycle(iter(it).__next__ for it in iterables)
nexts = cycle(iter(it).__next__ for it in iterables)
while
pending
:
while
num_active
:
try:
try:
for next in nexts:
for next in nexts:
yield next()
yield next()
except StopIteration:
except StopIteration:
pending -= 1
# Remove the iterator we just exhausted from the cycle.
nexts = cycle(islice(nexts, pending))
num_active -= 1
nexts = cycle(islice(nexts, num_active))
def partition(pred, iterable):
def partition(pred, iterable):
'Use a predicate to partition entries into false entries and true entries'
'Use a predicate to partition entries into false entries and true entries'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment