]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Docs: Clarify the before_and_after() example (GH-28458) (#28464)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 20 Sep 2021 01:53:37 +0000 (18:53 -0700)
committerPablo Galindo <pablogsal@gmail.com>
Wed, 29 Sep 2021 11:31:16 +0000 (12:31 +0100)
(cherry picked from commit fcbf9b176b1190301c760a921601c6488ef8b070)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Doc/library/itertools.rst
Lib/test/test_itertools.py

index bf60a0cee795f40cebc08cf0406daf491b9cd626..8341ce321b1b204b3e13d8bf5f4f0d33ccacd970 100644 (file)
@@ -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
index 6f8f87684e29cf1f9af529bf16a98e3ba8d9250c..3f4fb4cf071889505cd5c65ebfe68a5abd154529 100644 (file)
@@ -2604,10 +2604,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]))