8000 [3.12] Fix iter_index() to work with lists which do not support stop=… · python/cpython@778d094 · GitHub
[go: up one dir, main page]

Skip to content

Commit 778d094

Browse files
[3.12] Fix iter_index() to work with lists which do not support stop=None. (gh-109306) (#109310)
Fix iter_index() to work with lists which do not support stop=None. (gh-109306) (cherry picked from commit f2a55fe) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
1 parent 7479a7a commit 778d094

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Doc/library/itertools.rst

Lines changed: 11 additions & 0 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ which incur interpreter overhead.
877877
yield i
878878
else:
879879
# Fast path for sequences
880+
stop = len(iterable) if stop is None else stop
880881
i = start - 1
881882
try:
882883
while True:
@@ -1347,6 +1348,16 @@ The following recipes have a more mathematical flavor:
13471348
Traceback (most recent call last):
13481349
...
13491350
ValueError
1351+
>>> # Verify that both paths can find identical NaN values
1352+
>>> x = float('NaN')
1353+
>>> y = float('NaN')
1354+
>>> list(iter_index([0, x, x, y, 0], x))
1355+
[1, 2]
1356+
>>> list(iter_index(iter([0, x, x, y, 0]), x))
1357+
[1, 2]
1358+
>>> # Test list input. Lists do not support None for the stop argument
1359+
>>> list(iter_index(list('AABCADEAF'), 'A'))
1360+
[0, 1, 4, 7]
13501361

13511362
>>> list(sieve(30))
13521363
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

0 commit comments

Comments
 (0)
0