sorting a tuple

Quinn Dunkan quinn at upchuck.ugcs.caltech.edu
Tue Nov 14 21:47:34 EST 2000


On Wed, 15 Nov 2000 01:13:21 GMT, etsang at my-deja.com <etsang at my-deja.com> wrote:
>I forgot to mention that the tuple is only containg integers. E.g.
>items = ('1','2','3','4','5','6')
...
>And I want to sort it in decending order with a built in library
>funciton if possible to make code clean

There are no integers in that tuple :)  But, to sort it:

def rev_sort(x):
    y = list(x)
    y.sort()
    y.reverse()
    return y

Answers to possible questions you may have:
Q: "Why must I copy the tuple to a list?"
A: Tuples cannot be modified.  That's the whole point.
Q: Isn't there a nicer way to reverse sort?
A: No.  See the FAQ (this way *is* nice).



More information about the Python-list mailing list