Python 1.5.2 list sorting bug

Christian Tismer tismer at appliedbiometrics.com
Thu Oct 28 18:21:01 EDT 1999


Brian Kelley wrote:
> 
> actually a much quicker test is:
> 
> Python 1.5.2 (#1, Oct 27 1999, 17:21:07) [C] on irix646
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> a = [3,4,5,1,2]
> >>> a.sort(lambda x,y: x>y)
> >>> a
> [3, 4, 5, 1, 2]
> >>>

Please have a look into the documentation about sorting and
the cmp function. Actually, you need a three valued compare.

Using 

>>> a.sort(lambda x,y: cmp(x,y))

should convince you :-)

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101   :    *Starship* http://starship.python.net
10553 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home




More information about the Python-list mailing list