I just discovered the py3k range method count():
counts = range(start, stop, step).count(item)
Is not the result of the method always 1 or 0 ?. It seems to me a bit overkilling to call the method count (instead of maybe contains).
Is there something in this method that makes it different to the good old:
if item in range(start, stop, step) ?
range.count()indeed always returns 0 or 1, and it’s the same asint(item in range(...)). Its main purpose is to make the interface ofrange()objects comply with the interface of acollections.abc.Sequence, which requires acount()method.Note that
issubclass(range, collections.abc.Sequence)returnsTrue.