[Zope] Sorting a list of nested lists

Casey Duncan casey at zope.com
Mon Feb 9 15:40:56 EST 2004


On Mon, 9 Feb 2004 15:25:26 -0500 (EST)
Asad Habib <ahabib at engin.umich.edu> wrote:

> Hello. Does anyone know what happens when you apply the list sort
> operation to a list that contains lists? In this case, what does
> Python use as the sort criteria? Any help would be greatly
> appreciated. Thanks.
> 
> - Asad

It is similar to sorting a list of strings. See:

http://www.python.org/doc/current/ref/comparisons.html

"""
Tuples and lists are compared lexicographically using comparison of
corresponding elements. This means that to compare equal, each element
must compare equal and the two sequences must be of the same type and
have the same length.

If not equal, the sequences are ordered the same as their first
differing elements. For example, cmp([1,2,x], [1,2,y]) returns the same
as cmp(x,y). If the corresponding element does not exist, the shorter
sequence is ordered first (for example, [1,2] < [1,2,3]). 
"""

hth,

-Casey



More information about the Zope mailing list