Python 1.5.2 list sorting bug

Andrew M. Kuchling akuchlin at mems-exchange.org
Thu Oct 28 18:12:47 EDT 1999


Brian Kelley <kelley at bioreason.com> writes:
> >>> a = [3,4,5,1,2]
> >>> a.sort(lambda x,y: x>y)
> >>> a
> [3, 4, 5, 1, 2]

Note that the function supplied to sort is supposed to only return 0 when 
x and y are equal, and return +/-1 depending on which value is larger.  
Try lambda x,y: cmp( len(x), len(y) ) instead.

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
We must avoid duplication of effort, because that is being done by others.
    -- Arthur Mitchell




More information about the Python-list mailing list