A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-August/017174.html below:

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

[Python-Dev] PEP 265 - Sorting Dictionaries by ValueBarry 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.

		Barry




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4