compare range objects

Ian Kelly ian.g.kelly at gmail.com
Fri Oct 21 02:54:45 EDT 2011


On Thu, Oct 20, 2011 at 8:16 PM, Chris Angelico <rosuav at gmail.com> wrote:
> Hmm. I wonder would slice objects be appropriate? They're comparable:
>
>>>> a=slice(1,10)
>>>> b=slice(1,10)
>>>> a==b
> True
>
> They're not iterable though - not directly (but you could slice
> range(maxint) down to size). You could possibly use itertools.islice
> objects for a similar job, but they're not comparable.

They have completely different semantics for negative numbers.
range(-7, 10) and range(maxint)[slice(-7, 10)] are two completely
different things.

Still, though, if slice objects are directly comparable, I can't see
any reason why range objects shouldn't be.

Cheers,
Ian



More information about the Python-list mailing list