Python 1.5.2 list sorting bug

Brian Kelley kelley at bioreason.com
Thu Oct 28 17:26:55 EDT 1999


Could someone help me verify this?  I ran into this bug on SGI Python
1.5.2, Solaris Python 1.5.2 and linux Python 1.5.2 but not on Python
1.5.1 on the same platforms...  The problem seems to be that sorting a
list using a lambda function is broken.  If code snippet doesn't raise
an AssertionError all is well.

class foo:
    def __init__(self, size):
        self.data = range(size)

unsorted = [ foo(47), foo(47), foo(57), foo(49), foo(40), foo(54) ]

sorted = unsorted[:]
sorted.sort(lambda x,y: len(x.data) > len(y.data))

print "sorted?"
old_mol = sorted[0]
for mol in sorted[1:]:
    print len(mol.data)
    assert len(mol.data) >= len(old_mol.data), "List not sorted
correctly"
    old_mol = mol





--
Brian Kelley          w 505 995-8188
Bioreason, Inc        f 505 995-8186
309 Johnson Av
Santa Fe, NM 87501    kelley at bioreason.com







More information about the Python-list mailing list