Social problems of Python doc [was Re: Python docs disappointing]

Raymond Hettinger python at rcn.com
Wed Aug 12 17:24:29 EDT 2009


[Raymond Hettinger]
> Here are a few thoughts on list.sort() for those who are interested:

After one more reading of Xah Lee's posts on the documentation for
sort,
here are couple more thoughts:

* The reason that list.sort() allows None for the cmp parameter is not
so that you can write list.sort(None).  It was put there to make it
easier for people writing function definitions where the cmp function
is a possible argument:

   def sort_and_chop(seq, maxlen, cmp=None):
       s = seq[:]
       s.sort(cmp)           # needs to accept None as a possible
argument
       return s[:maxlen]

* The reason for implementing the key= parameter had nothing to do
with limitations of Python's compiler.  Instead, it was inspired by
the
decorate-sort-undecorate pattern.


Raymond



More information about the Python-list mailing list