[Python-Dev] PEP 265 - Sorting Dictionaries by Value

Barry Scott barry@scottb.demon.co.uk
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?
  "index=4,accending field=5,case-blind,decending"
  sort by index 4 accending then by field=5 case blind comparison.