[Python-ideas] Implement comparison operators for range objects

Ian Kelly ian.g.kelly at gmail.com
Wed Oct 12 15:24:31 EDT 2011


On Wed, Oct 12, 2011 at 11:51 AM, MRAB <python at mrabarnett.plus.com> wrote:
>> Aside:
>>
>> I'm astonished to see that range objects have a count method! What's the
>> purpose of that? Any value's count will either be 0 or 1, and a more
>> appropriate test would be `value in range`:
>>
>>  >>> 17 in range(2, 30, 3) # like r.count(17) => 1
>> True
>>  >>> 18 in range(2, 30, 3) # like r.count(18) => 0
>> False
>>
> In Python 2, range returns a list, and lists have a .count method.
> Could that be the reason?

Python 2 xrange objects do not have a .count method.  Python 3 range
objects do have a .count method.  The addition is curious, to say the
least.



More information about the Python-list mailing list