https://github.com/python/cpython/commit/a370eebdd9bcc18d39f9e5d886ddb91a2435033e
commit: a370eebdd9bcc18d39f9e5d886ddb91a2435033e
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: rhettinger <[email protected]>
date: 2024-05-18T01:51:20-05:00
summary:

[3.12] Minor improvements to the docs for itertools.tee() (gh-119135) 
(gh-119137)

files:
M Doc/library/itertools.rst

diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 183aa36d927550..cf2bbf0b1ae60a 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -690,18 +690,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

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to