Class-override of a sort-key method?

pythonlist.calin79 at spamgourmet.com pythonlist.calin79 at spamgourmet.com
Mon Dec 20 18:23:16 EST 2010


Hi all - it would seem that these days, all the cool kids use the sort
function's 'key' kwarg in order to sort a list of custom objects quickly.

Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to
get 'automatic sorting' in a similar fashion, there doesn't seem to be a
direct analogue for a class-overridable method for providing a sort key.
 (ie, something like '__sortkey__' or '__key__').

Is there one, and I'm just missing it? If not, are there any plans to add
one? (I did a quick search of the PEP list, and the only hits for 'sort' I
saw had to do with sorting dictionaries by value).

- Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101220/e52ad480/attachment-0001.html>


More information about the Python-list mailing list