[FRPythoneers] sorting a list of dictionaries

Uche Ogbuji uche.ogbuji at fourthought.com
Tue Jan 21 14:55:22 MST 2003

> Excellent.  That did the trick.  I sorted on cn instead of sn, givenName,
> since that's how we sort lists around here.  I'll throw my script at the
> bottom of the message for those who are interested.  Python is cool.
> I used Jack's cmp solution since that way I don't have to modify the list
> again to remove the [0] element. The last name coincidence has nothing to
> do with it.  :)

I'm sorry I haven't had time to follow this thread clearly, but in case it's 
handy, I wanted to point out that any time you are tempted to use sort() with 
a function argument, and performance is an issue, you want to at least 
consider the DSU pattern.  See:


I think they use list comprehension examples, but DSU can be mplemented using 
map and lambda as well, for 1.5.2 support.

I do recomment moving to Python 2.2. ASAP, though.  Ther are wonderful 
additions and improvements.

Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
Python Generators + DOM - http://www.xml.com/pub/a/2003/01/08/py-xml.html
4Suite Repository Features - https://www6.software.ibm.com/reg/devworks/dw-x4su
XML class warfare - http://www.adtmag.com/article.asp?id=6965
MusicBrainz  metadata - http://www-106.ibm.com/developerworks/xml/library/x-thi

More information about the FRPythoneers mailing list