diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2023-09-12 02:04:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-12 02:04:28 (GMT) |
commit | f2a55fecd063244a5fd09a38f673f0781f8802d1 (patch) | |
tree | 042ab591d613f0673dd2a845037ebf4274f7d920 | |
parent | 7dedfd36dc16d9e1e15d7d0b0a636dd401a5a543 (diff) | |
download | cpython-f2a55fecd063244a5fd09a38f673f0781f8802d1.zip cpython-f2a55fecd063244a5fd09a38f673f0781f8802d1.tar.gz cpython-f2a55fecd063244a5fd09a38f673f0781f8802d1.tar.bz2 |
Fix iter_index() to work with lists which do not support stop=None. (gh-109306)
-rw-r--r-- | Doc/library/itertools.rst | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 3cfc260..5e187ae 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -877,6 +877,7 @@ which incur interpreter overhead. yield i else: # Fast path for sequences + stop = len(iterable) if stop is None else stop i = start - 1 try: while True: @@ -1345,6 +1346,16 @@ The following recipes have a more mathematical flavor: Traceback (most recent call last): ... ValueError + >>> # Verify that both paths can find identical NaN values + >>> x = float('NaN') + >>> y = float('NaN') + >>> list(iter_index([0, x, x, y, 0], x)) + [1, 2] + >>> list(iter_index(iter([0, x, x, y, 0]), x)) + [1, 2] + >>> # Test list input. Lists do not support None for the stop argument + >>> list(iter_index(list('AABCADEAF'), 'A')) + [0, 1, 4, 7] >>> list(sieve(30)) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] |