josh logan wrote:
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
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?
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?
twice:
ordered = sorted(players, key=lambda p: p.fname, reverse=True)
ordered.sort(ke y=lambda p: p.lname)
Peter