[Tutor] Re: Sorting ranges
Christopher Smith
csmith@blakeschool.org
Wed, 05 Sep 2001 07:04:50 -0500
tzuming wrote:
>
>does anyone know how to sort ranges in ascending order? Eg.
>
>780=>1014 range 1
>771=>1014 range 2
>29=>214 range 3
>226=>426 range 4
>
>I would like my output to look like this:
>
>29=>214
>226=>426
>771=>1014
>780=>1014
>
Just create a list of these ranges and sort them:
>>> r1=range(780,1015)
>>> r2=range(771,1015)
>>> r3=range(29,215)
>>> r4=range(226,427)
>>> all=[r1,r2,r3,r4] #here is the list of ranges
>>> all.sort() #here we sort them
>>> for a in all:
... print a[0:2],'...'
...
[29, 30] ...
[226, 227] ...
[771, 772] ...
[780, 781] ...
>>>
/c