Skip to content

Commit

Permalink
Docs: Clarify the before_and_after() example (GH-28458) (#28464)
Browse files Browse the repository at this point in the history
(cherry picked from commit fcbf9b1)

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

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
  • Loading branch information
2 people authored and pablogsal committed Sep 29, 2021
1 parent 2e4d66d commit 0a74d33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Doc/library/itertools.rst
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions Lib/test/test_itertools.py
Expand Up @@ -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]))
Expand Down

0 comments on commit 0a74d33

Please sign in to comment.