[issue11712] Doc list.sort(cmp=,key=) result.

Terry J. Reedy report at bugs.python.org
Tue Mar 29 21:28:42 CEST 2011


New submission from Terry J. Reedy <tjreedy at udel.edu>:

l=[1,3,2]
l.sort(cmp=lambda x,y:y-x, key=lambda x: x)
print(l)

With CPython 2.7 this
1) could raise an exception like TypeError: conflicting arguments passed;
2) could ignore cmp= and print [1,2,3] on the basis that the new should override the old;
3) does ignore key= and prints [3,2,1] (why does not matter now),
but as near as I can tell, this is not documented.

Suggestion: in 5.6.4. Mutable Sequence Types, in footnote 8, after
"key specifies a function of one argument that is used to extract a comparison key from each list element: key=str.lower. The default value is None."
add "Ignored if *cmp* is also given."

----------
assignee: docs at python
components: Documentation
keywords: easy, patch
messages: 132507
nosy: docs at python, terry.reedy
priority: normal
severity: normal
stage: needs patch
status: open
title: Doc list.sort(cmp=,key=) result.
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11712>
_______________________________________


More information about the Python-bugs-list mailing list