Commit 5d332bbd authored by Raymond Hettinger's avatar Raymond Hettinger

Simpler documentation for itertools.tee(). Should be backported.

parent cb78de6d
...@@ -361,16 +361,15 @@ loops that truncate the stream. ...@@ -361,16 +361,15 @@ loops that truncate the stream.
is equivalent to:: is equivalent to::
def tee(iterable): def tee(iterable):
def gen(next, data={}, cnt=[0]): def gen(next, data={}):
for i in count(): for i in count():
if i == cnt[0]: if i in data:
item = data[i] = next() yield data.pop(i)
cnt[0] += 1
else: else:
item = data.pop(i) data[i] = next()
yield item yield data[i]
it = iter(iterable) 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 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 used anywhere else; otherwise, the *iterable* could get advanced without the tee
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment