summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2024-02-29 17:30:18 (GMT)
committerGitHub <noreply@github.com>2024-02-29 17:30:18 (GMT)
commita81d9509ee60c405e08012aec5d97da5840b590b (patch)
tree77a36e4c9017c79bded28ef9cd9da7d1f4577f22
parentf0df35eeca2ccdfd58cfb9801f06ffa23537270b (diff)
downloadcpython-a81d9509ee60c405e08012aec5d97da5840b590b.zip
cpython-a81d9509ee60c405e08012aec5d97da5840b590b.tar.gz
cpython-a81d9509ee60c405e08012aec5d97da5840b590b.tar.bz2
Make the iter_except() recipe more compact. (gh-116132)
Only one example is needed
-rw-r--r--Doc/library/itertools.rst21
1 files changed, 1 insertions, 20 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index c26f6c8..072fe02 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -983,28 +983,10 @@ which incur interpreter overhead.
""" Call a function repeatedly until an exception is raised.
Converts a call-until-exception interface to an iterator interface.
- Like builtins.iter(func, sentinel) but uses an exception instead
- of a sentinel to end the loop.
-
- Priority queue iterator:
- iter_except(functools.partial(heappop, h), IndexError)
-
- Non-blocking dictionary iterator:
- iter_except(d.popitem, KeyError)
-
- Non-blocking deque iterator:
- iter_except(d.popleft, IndexError)
-
- Non-blocking iterator over a producer Queue:
- iter_except(q.get_nowait, Queue.Empty)
-
- Non-blocking set iterator:
- iter_except(s.pop, KeyError)
-
"""
+ # iter_except(d.popitem, KeyError) --> non-blocking dictionary iterator
try:
if first is not None:
- # For database APIs needing an initial call to db.first()
yield first()
while True:
yield func()
@@ -1012,7 +994,6 @@ which incur interpreter overhead.
pass
-
The following recipes have a more mathematical flavor:
.. testcode::