[Tutor] sorting complicated lists

Sean 'Shaleh' Perry shaleh@valinux.com
Fri, 23 Jun 2000 16:06:05 -0700 (PDT)

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

def ldap-sorter(a, b):
        return cmp(a[1]['sn'], b[1]['sn'])


is what is actually happening (more or less).  lamda makes a psuedo function
in-place.  cmp() is analogous to strcmp() in C (and others).  Basically you
want to return -1, 0, or 1.  -1 if a is less than b, 0 is they are equal and 1
is b is less than a.  I may have it backwards with regards to less than v.
greater than.