sorting a tuple

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

<etsang at> wrote in message news:8usna1$2fo$1 at
> 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
> 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:

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,


More information about the Python-list mailing list