[issue9213] range purports to implement the Sequence ABC, but is missing index and count methods
Daniel Urban
report at bugs.python.org
Wed Jul 21 22:25:21 CEST 2010
Daniel Urban <urban.dani+py at gmail.com> added the comment:
The attached patch adds the range.count and range.index methods.
Pseudocode for the two method:
def count(self, ob):
if ob in self:
return 1
else:
return 0
def index(self, ob, start=0, stop=len(self)):
if ob in self:
idx = (ob - self.start) // self.step
if start < 0:
start = start + len(self)
if stop < 0:
stop = stop + len(self)
if start <= idx < stop:
return idx
raise ValueError("{!r} is not in range".format(ob))
----------
keywords: +patch
nosy: +durban
Added file: http://bugs.python.org/file18111/issue9213.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9213>
_______________________________________
More information about the Python-bugs-list
mailing list