Docs: Clarify the before_and_after() example (GH-28458) (#28464)

(cherry picked from commit fcbf9b176b)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2021-09-19 18:53:37 -07:00 committed by Pablo Galindo
parent 2e4d66d2e7
commit 0a74d33e14
No known key found for this signature in database
GPG key ID: FFE87404168BD847
2 changed files with 8 additions and 6 deletions

View 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

View file

@ -2604,10 +2604,11 @@ def test_permutations_sizeof(self):
>>> 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]))