summaryrefslogtreecommitdiffstats
path: root/Doc/library/itertools.rst
diff options
context:
space:
mode:
authorStefan Pochmann <609905+pochmann@users.noreply.github.com>2023-03-02 03:16:23 (GMT)
committerGitHub <noreply@github.com>2023-03-02 03:16:23 (GMT)
commiteaae563b6878aa050b4ad406b67728b6b066220e (patch)
treeb1bd7d9491f50264244b8a3f5f3eda0e32d78687 /Doc/library/itertools.rst
parent2f62a5da949cd368a9498e6a03e700f4629fa97f (diff)
downloadcpython-eaae563b6878aa050b4ad406b67728b6b066220e.zip
cpython-eaae563b6878aa050b4ad406b67728b6b066220e.tar.gz
cpython-eaae563b6878aa050b4ad406b67728b6b066220e.tar.bz2
gh-102088 Optimize iter_index itertools recipe (GH-102360)
Diffstat (limited to 'Doc/library/itertools.rst')
-rw-r--r--Doc/library/itertools.rst9
1 files changed, 6 insertions, 3 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 95da716..d85a17e 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -886,9 +886,12 @@ which incur interpreter overhead.
except AttributeError:
# Slow path for general iterables
it = islice(iterable, start, None)
- for i, element in enumerate(it, start):
- if element is value or element == value:
- yield i
+ i = start - 1
+ try:
+ while True:
+ yield (i := i + operator.indexOf(it, value) + 1)
+ except ValueError:
+ pass
else:
# Fast path for sequences
i = start - 1