sorting on keys in a list of dicts
exarkun at divmod.com
Thu Jan 6 15:40:01 CET 2005
On Thu, 06 Jan 2005 15:31:22 +0100, J Berends <j.p.t.j.berends@[n0sp4m].nl> wrote:
>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.
In Python 2.4,
In Python 2.3,
L2 = [(d[key], i, d) for (i, d) in enumerate(L)]
L = [d for (v, i, d) in L2]
More information about the Python-list