[Python-ideas] Implement comparison operators for range objects

Jim Jewett jimjjewett at gmail.com
Thu Oct 13 16:12:08 CEST 2011


On Wed, Oct 12, 2011 at 11:18 PM, Guido van Rossum <guido at python.org> wrote:

> The open question so far is: How do we want our ranges to work? My
> intuition is weak, but says: range(0) != range(1, 1) != range(1, 1, 2)
> and range(0, 10, 2) != range(0, 11, 2); all because the arguments
> (after filling in the defaults) are different, and those arguments can
> come out using the start, stop, step attributes (once we implement
> them :-).

If range were a normal function, we would compare the output of the
function call without worrying about what the inputs were.

If range were tuple, then the exact inputs would matter, but it isn't.

The few times I wanted to compare ranges, I cared what sequence they
produced, and *wanted* it to normalize out the arguments for me.  That
said, it was years ago, and I can't even remember whether or not I was
working on a "real-world" problem at the time.

-jJ



More information about the Python-ideas mailing list