list.sort(cmpfunc) question

Joshua Marshall jmarshal at mathworks.com
Fri Mar 16 11:33:49 EST 2001


Aahz Maruch <aahz at panix.com> wrote:
> In article <m1ae6lg5qt.fsf at pclabs188.labs.trema.com>,
> Harri Pasanen  <harri at trema.com> 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