compare range objects

Hans Mulder hansmu at xs4all.nl
Thu Oct 20 14:00:57 EDT 2011


On 20/10/11 18:22:04, Westley Martínez wrote:
> On Thu, Oct 20, 2011 at 06:19:40AM -0700, Yingjie Lan wrote:
>> Hi,
>>
>> Is it possible to test if two range objects contain the same sequence of integers by the following algorithm in Python 3.2?
>>
>> 1. standardize the ending bound by letting it be the first excluded integer for the given step size.
>> 2. compare the standardized starting bound, ending bound and step size: two ranges equal if and only if this triplet is the same.
>>
>> If that's correct, it would be good to have equality comparison on two ranges.
>>
>> Further, it might also be good to have sub-sequence test on ranges without enumerating it.
>>
>
> There's already a discussion about this on python-ideas.  But somebody
> please tell me, why would you ever need to compare ranges?

It could be useful if you're unit-testing a function that returns a range.


-- HansM



More information about the Python-list mailing list