mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
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:
parent
0e96086805
commit
697b6650ed
2 changed files with 8 additions and 6 deletions
|
|
@ -859,10 +859,11 @@ which incur interpreter overhead.
|
||||||
""" Variant of takewhile() that allows complete
|
""" Variant of takewhile() that allows complete
|
||||||
access to the remainder of the iterator.
|
access to the remainder of the iterator.
|
||||||
|
|
||||||
>>> all_upper, remainder = before_and_after(str.isupper, 'ABCdEfGhI')
|
>>> it = iter('ABCdEfGhI')
|
||||||
>>> str.join('', all_upper)
|
>>> all_upper, remainder = before_and_after(str.isupper, it)
|
||||||
|
>>> ''.join(all_upper)
|
||||||
'ABC'
|
'ABC'
|
||||||
>>> str.join('', remainder)
|
>>> ''.join(remainder) # takewhile() would lose the 'd'
|
||||||
'dEfGhI'
|
'dEfGhI'
|
||||||
|
|
||||||
Note that the first iterator must be fully
|
Note that the first iterator must be fully
|
||||||
|
|
|
||||||
|
|
@ -2605,10 +2605,11 @@ def test_permutations_sizeof(self):
|
||||||
>>> list(odds)
|
>>> list(odds)
|
||||||
[1, 3, 5, 7, 9]
|
[1, 3, 5, 7, 9]
|
||||||
|
|
||||||
>>> all_upper, remainder = before_and_after(str.isupper, 'ABCdEfGhI')
|
>>> it = iter('ABCdEfGhI')
|
||||||
>>> str.join('', all_upper)
|
>>> all_upper, remainder = before_and_after(str.isupper, it)
|
||||||
|
>>> ''.join(all_upper)
|
||||||
'ABC'
|
'ABC'
|
||||||
>>> str.join('', remainder)
|
>>> ''.join(remainder)
|
||||||
'dEfGhI'
|
'dEfGhI'
|
||||||
|
|
||||||
>>> list(powerset([1,2,3]))
|
>>> list(powerset([1,2,3]))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue