Re: Question about sorted in Python 3.0rc1

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Otten

    Re: Question about sorted in Python 3.0rc1

    josh logan wrote:
    A better example would be sorting by increasing last name and
    decreasing first name. This would be easy with the sort function
    comparator, but I can't see how to do the same with the key argument.
    Is the only solution to decorate the Player objects in another class
    that has the appropriate __cmp__ function (or whatever is needed) and
    then retrieve the Player objects back?
    Python's sort algorithm is guaranteed to be stable; therefore you can sort
    twice:

    ordered = sorted(players, key=lambda p: p.fname, reverse=True)
    ordered.sort(ke y=lambda p: p.lname)

    Peter
Working...