[Python-ideas] Implement comparison operators for range objects

Matt Joiner anacrolix at gmail.com
Sat Oct 15 07:19:50 CEST 2011


+0 =)

On Sat, Oct 15, 2011 at 1:07 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 10/14/2011 1:23 PM, Guido van Rossum wrote:
>>
>> We've been bikeshedding long enough. I propose to do the following to
>> range() in Python 3.3:
>>
>> - add read-only attributes .start, .step, .stop
>> - add slicing such that it normalizes .stop to .start + the right
>> multiple of .step
>> - add __eq__ and __hash__ which compare by .start, .step, .stop
>
> I have sometimes thought that we should unify slice and range objects by
> either adding .__iter__ to slice objects or adding the necessary attributes
> to range objects. The proposal above comes close to doing the latter. I
> presume that slice.__eq__ does what you propose for range. All that would be
> missing from range is the slice.indices method.
>
> Both range and slice objects represent a virtual subseqeunce of ints with
> the same three attributes. We use one to explicitly iterate. We use the
> other to select subsequences with an internal iteration.
>
> If range.stop were allowed to be None, as is slice.stop, we also would not
> need itertools.count, which is the third way we represent a virtual stepped
> subsequence of ints.
>
> --
> Terry Jan Reedy
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



More information about the Python-ideas mailing list