sorting on keys in a list of dicts

Paul Rubin http
Thu Jan 6 09:40:28 EST 2005


J Berends <j.p.t.j.berends@[N0SP4M].nl> writes:
> Suppose I have a list of dictionaries and each dict has a common
> keyname with a (sortable) value in it.
> 
> How can I shuffle their position in the list in such way that they
> become sorted.

Do I understand the question right?  Can't you just say

  thelist.sort(lambda x,y: cmp(x['keyname'], y['keyname']))

or something like that?



More information about the Python-list mailing list