sorting a tuple

June Kim junaftnoon at nospamplzyahoo.com
Wed Nov 15 02:27:39 CET 2000


<etsang at my-deja.com> wrote in message news:8usna1$2fo$1 at nnrp1.deja.com...
> Hi,
>
> Can anyone tell me if there is any library function to srot a tuple ind
> ecending order? if not, can someone supply the code???
> thanks
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

You can't sort a tuple IN PLACE. You should copy it to a list and proceed.
There are several possible ways doing the descending order sorting and
this is one of them:

tuple=(100,4,59,1000,82)
tosort= list(tuple)
tosort.sort(lambda x,y:-cmp(x,y))

p.s. You could reverse the list with the built-in reverse() instead of using
customized sort.

Best regards,

June




More information about the Python-list mailing list