[Tutor] Sorting ranges

alan.gauld@bt.com alan.gauld@bt.com
Thu, 6 Sep 2001 14:48:25 +0100


> does anyone know how to sort ranges in ascending order? 

Nope, not even without Python.

What happens if the ranges overlap? What if one range is 
a subset of another?

Eg. 
> 780=>1014  range 1
> 771=>1014  range 2
> I would like my output to look like this:
> 771=>1014
> 780=>1014

OK, This implies you want the size of the first element
to be the determining factor in which case you could 
define your own comparison function (__cmp__() I guess?)
and just compare range1[0] with range2[0]...

You can then pass that as an extra parameter to the standard 
cmp function if I recall correctly. Theres definitely a way 
of doing that once you know how to write the __cmp__ bit.

Alan g