By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,775 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

sorting on keys in a list of dicts

P: n/a
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.
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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?
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.