mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Simpler documentation for itertools.tee(). Should be backported.
This commit is contained in:
parent
cb78de6d25
commit
5d332bbdee
1 changed files with 6 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue