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
2f08df36
Commit
2f08df36
authored
Oct 10, 2010
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10029: Fix sample code in the docs for zip().
parent
5b0e9e84
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
Doc/library/functions.rst
Doc/library/functions.rst
+12
-5
No files found.
Doc/library/functions.rst
View file @
2f08df36
...
@@ -1235,11 +1235,18 @@ are always available. They are listed here in alphabetical order.
...
@@ -1235,11 +1235,18 @@ are always available. They are listed here in alphabetical order.
iterable argument, it returns an iterator of 1-tuples. With no arguments,
iterable argument, it returns an iterator of 1-tuples. With no arguments,
it returns an empty iterator. Equivalent to::
it returns an empty iterator. Equivalent to::
def zip(*iterables):
def zip(*iterables):
# zip('ABCD', 'xy') --> Ax By
# zip('ABCD', 'xy') --> Ax By
iterables = map(iter, iterables)
sentinel = object()
while iterables:
iterables = [iter(it) for it in iterables]
yield tuple(map(next, iterables))
while iterables:
result = []
for it in iterables:
elem = next(it, sentinel)
if elem is sentinel:
return
result.append(elem)
yield tuple(result)
The left-to-right evaluation order of the iterables is guaranteed. This
The left-to-right evaluation order of the iterables is guaranteed. This
makes possible an idiom for clustering a data series into n-length groups
makes possible an idiom for clustering a data series into n-length groups
...
...
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