[Tutor] sorting complicated lists

Timothy Wilson wilson@visi.com
Fri, 23 Jun 2000 17:16:27 -0500 (CDT)


Hi everyone,

I'm working with python-ldap querying an ldap server to print employee phone
directories, for example. Here's an example of the data structure that
pyton-ldap returns using my record as an example (hope this wraps OK):

[('cn=WilsonT,ou=SIBLEY,o=ISD_197', {'revision': ['989'], 'givenName':
['Tim'], 'fullName': ['Tim Wilson'], 'mail': ['WilsonT@isd197.k12.mn.us'],
'postalCode': ['55118'], 'groupMembership':
['cn=Everyone,ou=SIBLEY,o=ISD_197', 'cn=GW52 Pilot,ou=SIBLEY,o=ISD_197',
'cn=TEACHERS PROGRAMS,ou=SIBLEY,o=ISD_197'], 'sn': ['Wilson'], 'street':
['1897 Delaware Avenue'], 'cn': ['WilsonT'], 'uid': ['WilsonT'], 'st':
['MN'], 'l': ['Sibley High School'], 'postalAddress': ['1897 Delaware
Avenue$Mendota Heights$MN$55118'], 'objectClass': ['top', 'person',
'organizationalPerson', 'inetOrgPerson'], 'description': ['Sibley'],
'physicalDeliveryOfficeName': ['Mendota Heights'], 'telephoneNumber':
['405-2428']})]

You can see that the result is a list with containing 1 item. That item is a
2-element tuple with the first element my 'cn' and the second a dictionary
containing all of the data in my ldap record.

If I retrieve 10 records, say, the list would consist of 10 tuples, one for
each record retrieved. Now the question:

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.)

-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/