list.sort(cmpfunc) question

Joshua Marshall jmarshal at
Fri Mar 16 17:33:49 CET 2001

Aahz Maruch <aahz at> wrote:
> In article <m1ae6lg5qt.fsf at>,
> Harri Pasanen  <harri at> wrote:
>>The list.sort(cmp) docs for Python 2.0 state:
>>   The sort() method takes an optional argument specifying a
>>   comparison function of two arguments (list items) which should
>>   return -1, 0 or 1 depending on whether the first argument is
>>   considered smaller than, equal to, or larger than the second
>>   argument.

> Note that "should" carefully.  The current implementation of sort() only
> checks for a negative value, but that's not a behavior that should be
> relied on in your coding.  You can be sure that any anamolies in the
> behavior of cmp() will be fixed if the sort() algorithm ever changes.

Seems the word "should" should never appear in documentation.

More information about the Python-list mailing list