compare range objects

Chris Angelico rosuav at gmail.com
Thu Oct 20 22:16:30 EDT 2011


On Fri, Oct 21, 2011 at 12:55 PM, Yingjie Lan <lanyjie at yahoo.com> wrote:
> In simulation, one can use range objects to denote a discrete domain,
> and domain comparison could be very useful. Not just equality, but also
> things like if one domain is contained in another.
>

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.

ChrisA



More information about the Python-list mailing list