sorting on keys in a list of dicts

J

J Berends

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.

Maybe I am doing it wrongly and you would say: why don't you get
yourself a (slimmed-down) implementation of a database class. But then
please guide me on the right path without having to install a xxSQL
server for my multiplatform code.
 
P

Paul Rubin

J Berends said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top