Sort list of dictionaries by key (case insensitive)

Stefan Behnel stefan_ml at
Wed Jan 13 16:26:42 CET 2010

Nico Grubert, 13.01.2010 16:18:
> print sorted(items, key=lambda d: locale.strxfrm(d.get('title')))
> -> [{'id': 2, 'title': 'The Storm'}, {'id': 4, 'title': 'The thunder'}, 
> {'id': 3, 'title': 'the bible'}, {'id': 1, 'title': 'the \xc4hnlich'}]
> The entry with the umlaut is the last item in but according to german 
> umlaut rules it should be the first item in the result.
> Do I have to set anything with the locale module?


More information about the Python-list mailing list