[Python-Dev] PEP 265 - Sorting Dictionaries by Value
Wed, 22 Aug 2001 20:25:05 +0100
Oh I like that!
> Or better still, list.sort() wouldn't need to be changed at all if
> there was a standard library module to create compison routines, e.g.
> from __future__ import nested_scopes
> def cmp_by_index(i):
> return lambda a, b: cmp((a[i], a), (b[i], b))
How should all the variations be handled?
* uses a naming convention and create the functions one by one?
cmp_by_index_accending - sort low to high at index n
cmp_by_index_decending - sort high to low at index n
cmp_by_field_accending - sort low to high at field n
cmp_by_field_decending - sort high to low at field n
... case blind, case sensitive versions...
* have a make_cmp function that takes a description and build
the cmp function on demand?
Would the description be a string with keywords in it?
sort by index 4 accending then by field=5 case blind comparison.