[Zope] sequence.sort from python
Dieter Maurer
dieter at handshake.de
Fri Oct 3 16:31:22 EDT 2003
Andrew Altepeter wrote at 2003-10-2 14:30 -0500:
> I am trying to use the sequence.sort function to sort the results from
> an ldap search (using the LDAPDelegate module from LDAPUserFolder to
> search ldap). This is in a custom python product, not in the zodb.
>
> Since every attribute value returned is a tuple, I can't exactly use
> sort's standard cmp function (at least it doesn't seem to work for me).
> I thought I'd try to use a custom comparison function, so I wrote my own
> to compare the first item in each attribute's tuple.
"sequence.sort" is made to sort a sequence of objects (instances)
according to some attribute values. It is not for
sorting tuples.
Python's "list.sort" may be what you are looking for.
It accepts a custom comparison function (x,y --> -1|0|1)
as optional parameter.
When your comparison function justs compares the first element
of a tuple, you can drop it as tuples are by default sorted
lexicographically.
Dieter
More information about the Zope
mailing list