[Python-ideas] Implement comparison operators for range objects

Georg Brandl g.brandl at gmx.net
Wed Oct 12 20:23:37 CEST 2011


Am 12.10.2011 20:04, schrieb Alexander Belopolsky:
> On Wed, Oct 12, 2011 at 1:58 PM, Mark Dickinson <dickinsm at gmail.com> wrote:
> ..
>> Should range(0, 10, 2) and range(0, 9, 2) be considered equal, or not?
> 
> I was going to ask the same question.  I think ranges r1 and r2 should
> be considered equal iff list(r1) == list(r2).  This is slightly harder
> to implement than just naively comparing (start, stop, step) tuples,
> but the advantage is that people won't run into surprises when they
> port 2.x code where result of range() is a list.

Definitely, yes.

Georg




More information about the Python-ideas mailing list