diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-09-20 01:53:37 (GMT) |
---|---|---|
committer | Pablo Galindo <pablogsal@gmail.com> | 2021-09-29 11:31:16 (GMT) |
commit | 0a74d33e14538849216271c3610ea4e301f7370f (patch) | |
tree | fd8240efc7eb31e037177b8cbe6be43c89e3c10a | |
parent | 2e4d66d2e71d36de394e0e7a4e60ed7b6a539933 (diff) | |
download | cpython-0a74d33e14538849216271c3610ea4e301f7370f.zip cpython-0a74d33e14538849216271c3610ea4e301f7370f.tar.gz cpython-0a74d33e14538849216271c3610ea4e301f7370f.tar.bz2 |
Docs: Clarify the before_and_after() example (GH-28458) (#28464)
(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>
-rw-r--r-- | Doc/library/itertools.rst | 7 | ||||
-rw-r--r-- | Lib/test/test_itertools.py | 7 |
2 files changed, 8 insertions, 6 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index bf60a0c..8341ce3 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 6f8f876..3f4fb4c 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -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])) |