[Tutor] sorting complicated lists
Timothy Wilson
wilson@visi.com
Fri, 23 Jun 2000 17:58:45 -0500 (CDT)
On Fri, 23 Jun 2000, Michael P. Reilly wrote:
> > How would I sort the list so I could print the results of the ldap query in
> > alphabetical order by surname? (That's the 'sn' key in the dictionary
> > above.)
>
> list.sort(lambda a, b: cmp(a[1]['sn'], b[1]['sn'])
>
> a (or b) = the tuple
> a[1] = the dictionary in the tuple
> a[1]['sn'] = the 'sn' slot in the dictionary
>
> References: Language Reference, 2.1.5.2 Mutable Sequence Types
> <URL:http://www.python.org/doc/current/lib/typesseq-strings.html#SECTION004152000000000000000>
Yikes! Time to hit the books. :-)
Seriously, thanks for the tip. It'll keep me busy for awhile.
-Tim
--
Tim Wilson | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN | | http://slashdot.org/
wilson@visi.com | <dtml-var pithy_quote> | http://linux.com/