Python 1.5.2 list sorting bug
Brian Kelley
kelley at bioreason.com
Thu Oct 28 18:47:31 EDT 1999
Christian Tismer wrote:
> 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 :-)
>
I'm convinced. As I mentioned, I don't know where I picked up the idiom
of:
a.sort(lambda x,y: x<y) and
a.sort(lambda x,y:y>x)
but I can assure you that now it has become:
a.sort(lambda x,y: cmp(y, x) ) and
a.sort(lambda x,y: cmp(x,y) )
or better yet forming the appropriate tupes and using a normal sort.
>
> 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
--
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