]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Docs: Clarify the before_and_after() example (GH-28458)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Mon, 20 Sep 2021 00:52:27 +0000 (19:52 -0500)
committerGitHub <noreply@github.com>
Mon, 20 Sep 2021 00:52:27 +0000 (19:52 -0500)
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 db6a98351bbd9bd79b20a8999e83b4f0b4f06a6b..4e1dd0255086b52d8d50530f5daf0a547e883357 100644 (file)
@@ -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]))