diff options
author | Raymond Hettinger <python@rcn.com> | 2010-10-10 05:56:57 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-10-10 05:56:57 (GMT) |
commit | 066e7a974afa8582fde9e1f97d76f76ee9ffc216 (patch) | |
tree | b53cceceb2fae512d0c3e90275d57bfe197d8d36 /Doc | |
parent | ae136da881bc185d7d4522518dffa870fc6518f4 (diff) | |
download | cpython-066e7a974afa8582fde9e1f97d76f76ee9ffc216.zip cpython-066e7a974afa8582fde9e1f97d76f76ee9ffc216.tar.gz cpython-066e7a974afa8582fde9e1f97d76f76ee9ffc216.tar.bz2 |
Issue #10029: Fix sample code in the docs for zip().
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/functions.rst | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index efcac08..e97be7b 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1220,11 +1220,18 @@ are always available. They are listed here in alphabetical order. iterable argument, it returns an iterator of 1-tuples. With no arguments, it returns an empty iterator. Equivalent to:: - def zip(*iterables): - # zip('ABCD', 'xy') --> Ax By - iterables = map(iter, iterables) - while iterables: - yield tuple(map(next, iterables)) + def zip(*iterables): + # zip('ABCD', 'xy') --> Ax By + sentinel = object() + iterables = [iter(it) for it in 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 makes possible an idiom for clustering a data series into n-length groups |