Skip to content

Commit f2a55fe

Browse files
authored
Fix iter_index() to work with lists which do not support stop=None. (gh-109306)
1 parent 7dedfd3 commit f2a55fe

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
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:
@@ -1345,6 +1346,16 @@ The following recipes have a more mathematical flavor:
13451346
Traceback (most recent call last):
13461347
...
13471348
ValueError
1349+
>>> # Verify that both paths can find identical NaN values
1350+
>>> x = float('NaN')
1351+
>>> y = float('NaN')
1352+
>>> list(iter_index([0, x, x, y, 0], x))
1353+
[1, 2]
1354+
>>> list(iter_index(iter([0, x, x, y, 0]), x))
1355+
[1, 2]
1356+
>>> # Test list input. Lists do not support None for the stop argument
1357+
>>> list(iter_index(list('AABCADEAF'), 'A'))
1358+
[0, 1, 4, 7]
13481359

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

0 commit comments

Comments
 (0)