Implement comparison operators for range objects

Mark Dickinson dickinsm at gmail.com
Fri Oct 14 11:33:01 EDT 2011


On Oct 12, 8:24 pm, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> On Wed, Oct 12, 2011 at 11:51 AM, MRAB <pyt... 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.

See http://bugs.python.org/issue9213

--
Mark



More information about the Python-list mailing list