Sort documentation inaccurate?

Sean 'Shaleh' Perry shalehperry at home.com
Wed Sep 26 08:12:46 CEST 2001


> 
> 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