Sort documentation inaccurate?

Bruce Dawson comments at cygnus-software.com
Thu Sep 27 02:26:16 EDT 2001


According to the documentation strcmp() would not be appropriate.
strcmp() does not return -1, 0, 1 it returns negative, zero, positive
and sort() expects -1, 0, 1.

I suspect that the documentation should either say:

    sort expects negative, zero, positive

or:

    sort expects negative or zero

but I don't know for sure.

Sean 'Shaleh' Perry wrote:

> >
> > On closer inspection the documentation says that the compare function is
> > supposed to return -1, 0 or 1. However this seems to be either
> > unnecessary, inaccurate, or both, since returning zero and one had no
> > effect, and returning 0 and -1 sorts the list perfectly.
> >
>
> It expects you to write a function similar to C(++)'s strcmp().  It return -1
> if x is less than y, 0 if they are equal, and 1 if x is greater than y.
>
> return x < y is either 0 or 1 so you never handle the actual truth of this case
> which should return -1.




More information about the Python-list mailing list