sorting on keys in a list of dicts

Peter Hansen peter at engcorp.com
Sat Jan 8 12:38:18 EST 2005


Nick Coghlan wrote:
> 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 

Assuming "key 1" refers to the first key, and "key 2" to the second
key, then I believe you meant "gives the effect of 'sort by key 2
then by key 1'".

In other words, if you have a stable sort algorithm and do one sort
operation using key 2, then a second sort operation using key 1,
it's the same as doing a single sort with the key combination "key 1, key 2",
not the other way around.

-Peter



More information about the Python-list mailing list