Python 1.5.2 list sorting bug

Skip Montanaro skip at mojam.com
Thu Oct 28 18:13:35 EDT 1999


    >>> a = [3,4,5,1,2]
    >>> a.sort(lambda x,y: x>y)
    >>> a
    [3, 4, 5, 1, 2]
    >>> 

I thought the comparison function was supposed to return -1, 0 or 1.  Yours
only returns 0 or 1.  See:

    http://www.python.org/doc/current/lib/typesseq-mutable.html

Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
847-971-7098   | Python: Programming the way Guido indented...




More information about the Python-list mailing list