sorting on keys in a list of dicts

Nick Coghlan ncoghlan at iinet.net.au
Fri Jan 7 10:34:18 EST 2005


Jeff Shannon wrote:
> I suppose that your version has the virtue that, if the sortkey value is 
> equal, items retain the order that they were in the original list, 
> whereas my version will sort them into an essentially arbitrary order. 
>  Is there anything else that I'm missing here?

Stability in sorting is a property not to be sneezed at - it means switching to 
sorting by a second key gives the effect of "sort by key 1, then by key 2", 
whereas that doesn't hold with an unstable sort algorithm. If you've ever used 
an application with an unstable sorting process and that only allows sorting a 
table on one column at a time, you'll appreciate the frustration that can cause :)

Also, it's required to match the behaviour of the Python 2.4 version (which gets 
to take advantage of the stability of the builtin sort).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list