summaryrefslogtreecommitdiff
path: root/Lib/_collections_abc.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/_collections_abc.py')
-rw-r--r--Lib/_collections_abc.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index 2f83543124..0ca7debddb 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -825,13 +825,23 @@ class Sequence(Sized, Iterable, Container):
for i in reversed(range(len(self))):
yield self[i]
- def index(self, value):
- '''S.index(value) -> integer -- return first index of value.
+ def index(self, value, start=0, stop=None):
+ '''S.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
'''
- for i, v in enumerate(self):
- if v == value:
- return i
+ if start is not None and start < 0:
+ start = max(len(self) + start, 0)
+ if stop is not None and stop < 0:
+ stop += len(self)
+
+ i = start
+ while stop is None or i < stop:
+ try:
+ if self[i] == value:
+ return i
+ except IndexError:
+ break
+ i += 1
raise ValueError
def count(self, value):