Replacing cmp with key for sorting
Arnaud Delobelle
arnodel at googlemail.com
Mon Nov 3 13:57:59 EST 2008
More information about the Python-list mailing list
Mon Nov 3 13:57:59 EST 2008
- Previous message (by thread): Replacing cmp with key for sorting
- Next message (by thread): Replacing cmp with key for sorting
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
bearophileHUGS at lycos.com writes: > Arnaud Delobelle: >> Here's another idea, probably more practical: >> >>> sorted(s, key=lambda x: tuple(256-ord(l) for l in x), reverse=True) > > Nice. > A variant that probably works with unicode strings too: > > print sorted(s, key=lambda x: [-ord(l) for l in x], reverse=True) Of course that's better! (although mine will work with unicode if yours does). It's funny how the obvious escapes me so often. Still I think the idea of the 'double reverse' (one letterwise, the other listwise) was quite good. -- Arnaud
- Previous message (by thread): Replacing cmp with key for sorting
- Next message (by thread): Replacing cmp with key for sorting
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list