[Tutor] Sorting ranges

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 5 Sep 2001 11:52:51 -0700 (PDT)


On Wed, 5 Sep 2001, Tzu-Ming Chern 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


Hello!  I'm guessing that:

###
29=>214
226=>426
771=>1014
780=>1014
###

is a sample of what a user can type into your program, since '=>' is not
part of Python syntax.

Can you explain a little more what you mean by "range"?  The reason I'm
asking is because Python uses the word "range" to mean a sequence of
numbers:

###
>>> range(0, 10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
###

so that might be causing some language confusion --- what we think of
"ranges" might be different from what you're thinking of.


Do you mean "pairs of numbers" instead?  That is, are you trying to sort:

###
[(780, 1014),
 (771, 1014),
 (29, 214),
 (226, 426)]
###

Just want to make sure we understand the problem better.