summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2024-05-18 06:32:34 (GMT)
committerGitHub <noreply@github.com>2024-05-18 06:32:34 (GMT)
commit81c3130c51a2b1504842cb1a93732cc03ddbbd79 (patch)
tree164c2dc0ce4aa9060b4d4aa17081aeadbc7eb319
parent31a28cbae0989f57ad01b428c007dade24d9593a (diff)
downloadcpython-81c3130c51a2b1504842cb1a93732cc03ddbbd79.zip
cpython-81c3130c51a2b1504842cb1a93732cc03ddbbd79.tar.gz
cpython-81c3130c51a2b1504842cb1a93732cc03ddbbd79.tar.bz2
Minor improvements to the docs for itertools.tee() (gh-119135)
-rw-r--r--Doc/library/itertools.rst21
1 files changed, 11 insertions, 10 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index a19baa3..6d33748 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -698,18 +698,19 @@ loops that truncate the stream.
def tee(iterable, n=2):
iterator = iter(iterable)
- empty_link = [None, None] # Singly linked list: [value, link]
- return tuple(_tee(iterator, empty_link) for _ in range(n))
+ shared_link = [None, None]
+ return tuple(_tee(iterator, shared_link) for _ in range(n))
def _tee(iterator, link):
- while True:
- if link[1] is None:
- try:
- link[:] = [next(iterator), [None, None]]
- except StopIteration:
- return
- value, link = link
- yield value
+ try:
+ while True:
+ if link[1] is None:
+ link[0] = next(iterator)
+ link[1] = [None, None]
+ value, link = link
+ yield value
+ except StopIteration:
+ return
Once a :func:`tee` has been created, the original *iterable* should not be
used anywhere else; otherwise, the *iterable* could get advanced without