Re: [Tutor] sorting a list of dictionaries

2005-04-15 Thread Kent Johnson
PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: Wednesday, April 13, 2005 3:52 AM Cc: tutor@python.org Subject: Re: [Tutor] sorting a list of dictionaries -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 09, 2004 12:19 PM

RE: [Tutor] sorting a list of dictionaries

2005-04-15 Thread Gooch, John
Satellite L.L.C. 9601 S. Meridian Blvd. Englewood, CO 80112 Desk: 720-514-5708 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: Wednesday, April 13, 2005 3:52 AM Cc: tutor@python.org Subject: Re: [Tutor] sorting a list of di

Re: [Tutor] sorting a list of dictionaries

2005-04-13 Thread Kent Johnson
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 09, 2004 12:19 PM To: tutor@python.org Subject: Re: [Tutor] sorting a list of dictionaries On 9 Dez 2004, [EMAIL PROTECTED] wrote: I have a list of dictionaries, each representing info about a

Re: [Tutor] sorting a list of dictionaries

2005-04-12 Thread Sean Perry
Gooch, John wrote: I am working on a dictionary sorting problem just like the one in the email thread at the bottom of this message. My question about their solution is: In these lines: lst.sort(lambda m, n: cmp(m.get(field), n.get(field))) where field is either 'name' or 'size'. Wh

RE: [Tutor] sorting a list of dictionaries

2005-04-12 Thread Gooch, John
;. What is "n:" and what is "lambda m" ? Thank You, John A. Gooch -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 09, 2004 12:19 PM To: tutor@python.org Subject: Re: [Tutor] sorting a list of dictionaries On 9 Dez 20

Re: [Tutor] sorting a list of dictionaries

2004-12-09 Thread Larry Holish
On Thu, Dec 09, 2004 at 03:22:29PM -0500, Kent Johnson wrote: > Using sort() with a user compare function is not recommended when you > care about performance. The problem is that the sort function has to > call back into Python code for every compare, of which there are many. > The decorate - sort

Re: [Tutor] sorting a list of dictionaries

2004-12-09 Thread Kent Johnson
Using sort() with a user compare function is not recommended when you care about performance. The problem is that the sort function has to call back into Python code for every compare, of which there are many. The decorate - sort - undecorate idiom is the preferred way to do this in Python < 2.4

Re: [Tutor] sorting a list of dictionaries

2004-12-09 Thread Karl Pflästerer
On 9 Dez 2004, [EMAIL PROTECTED] wrote: > I have a list of dictionaries, each representing info about a file, > something like: > > [{'name':'foo.txt','size':35}, {'name':'bar.txt','size':35}, ...] > > I want to present a sorted list of all the files' data, sorting on the > keys 'name' or 'size'.

Re: [Tutor] sorting a list of dictionaries

2004-12-09 Thread Kent Johnson
If you can use Python 2.4 it is very simple using the new key= parameter to sort and operator.itemgetter: >>> import operator >>> ds = [{'name':'foo.txt','size':35}, {'name':'bar.txt','size':36}] >>> ds.sort(key=operator.itemgetter('name')) >>> ds [{'name': 'bar.txt', 'size': 36}, {'name': 'foo.t