summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2021-09-20 00:52:27 (GMT)
committerGitHub <noreply@github.com>2021-09-20 00:52:27 (GMT)
commitfcbf9b176b1190301c760a921601c6488ef8b070 (patch)
tree5147e2be97e18e04fff0293016f61c1de66c872c
parenta6779715c4d0289acb59a8fd3660ab2e5d486c4b (diff)
downloadcpython-fcbf9b176b1190301c760a921601c6488ef8b070.zip
cpython-fcbf9b176b1190301c760a921601c6488ef8b070.tar.gz
cpython-fcbf9b176b1190301c760a921601c6488ef8b070.tar.bz2
Docs: Clarify the before_and_after() example (GH-28458)
-rw-r--r--Doc/library/itertools.rst7
-rw-r--r--Lib/test/test_itertools.py7
2 files changed, 8 insertions, 6 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index ac6b354..61d8b86 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -859,10 +859,11 @@ which incur interpreter overhead.
""" Variant of takewhile() that allows complete
access to the remainder of the iterator.
- >>> all_upper, remainder = before_and_after(str.isupper, 'ABCdEfGhI')
- >>> str.join('', all_upper)
+ >>> it = iter('ABCdEfGhI')
+ >>> all_upper, remainder = before_and_after(str.isupper, it)
+ >>> ''.join(all_upper)
'ABC'
- >>> str.join('', remainder)
+ >>> ''.join(remainder) # takewhile() would lose the 'd'
'dEfGhI'
Note that the first iterator must be fully
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index db6a983..4e1dd02 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -2646,10 +2646,11 @@ True
>>> list(odds)
[1, 3, 5, 7, 9]
->>> all_upper, remainder = before_and_after(str.isupper, 'ABCdEfGhI')
->>> str.join('', all_upper)
+>>> it = iter('ABCdEfGhI')
+>>> all_upper, remainder = before_and_after(str.isupper, it)
+>>> ''.join(all_upper)
'ABC'
->>> str.join('', remainder)
+>>> ''.join(remainder)
'dEfGhI'
>>> list(powerset([1,2,3]))