]> 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)
committerGitHub <noreply@github.com>
Mon, 20 Sep 2021 01:53:37 +0000 (20:53 -0500)
(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 ac6b354138b6e243ebc69e7ccb80cf6fbff0b60b..61d8b869711fa49b008c0ae6881697491d78b31c 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 aa81076f32d001b0b8e9eb1b974c957fb18bf453..a12f6f0b9773e4f9d31d7abc27babec4f75139e5 100644 (file)
@@ -2605,10 +2605,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]))