diff options
author | Raymond Hettinger <python@rcn.com> | 2007-12-29 22:09:34 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2007-12-29 22:09:34 (GMT) |
commit | 5d332bbdee032d6851e252b1238482c14b32212c (patch) | |
tree | 71c5e41aeec0aadc20e95c12bbc7798f22c22016 | |
parent | cb78de6d25591363e26610e168ec48e3e63757b0 (diff) | |
download | cpython-5d332bbdee032d6851e252b1238482c14b32212c.zip cpython-5d332bbdee032d6851e252b1238482c14b32212c.tar.gz cpython-5d332bbdee032d6851e252b1238482c14b32212c.tar.bz2 |
Simpler documentation for itertools.tee(). Should be backported.
-rw-r--r-- | Doc/library/itertools.rst | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index c1bffa4..9cb316d 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -361,16 +361,15 @@ loops that truncate the stream. is equivalent to:: def tee(iterable): - def gen(next, data={}, cnt=[0]): + def gen(next, data={}): for i in count(): - if i == cnt[0]: - item = data[i] = next() - cnt[0] += 1 + if i in data: + yield data.pop(i) else: - item = data.pop(i) - yield item + data[i] = next() + yield data[i] it = iter(iterable) - return (gen(it.next), gen(it.next)) + return gen(it.next), gen(it.next) Note, once :func:`tee` has made a split, the original *iterable* should not be used anywhere else; otherwise, the *iterable* could get advanced without the tee |