on sorting things

Eli the Bearded * at eli.users.panix.com
Thu Dec 19 02:31:38 EST 2019


I recently saw a link to an old post on a blog and then started looking
at the newer posts. This one:

https://leancrew.com/all-this/2019/11/the-key-to-sorting-in-python/

discusses ways to deal with useful sorting of movie / television show
titles. Some initial words should be re-ordered for sorting purposes
(_Adventures of Huckleberry Finn, The_), roman numbers should sort like
regular numbers (_Rocky V_ comes before _Rocky IX_), and something needs
to be done about sorting accented vowels. 

But what caught my eye most, as someone relatively new to Python but
with long experience in C in Perl, is sorting doesn't take a
*comparison* function, it takes a *key generator* function, and that
function is supposed to transform the thing into something that the
native comparison knows how to compare.

This seems a strange choice, and I'm wondering if someone can explain
the benefits of doing it that way to me.

Elijah
------
imagines it could make porting some code in or out of Python trickier


More information about the Python-list mailing list