Message132507
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." |
|
Date |
User |
Action |
Args |
2011-03-29 19:28:42 | terry.reedy | set | recipients:
+ terry.reedy, docs@python |
2011-03-29 19:28:42 | terry.reedy | set | messageid: <1301426922.02.0.157603577623.issue11712@psf.upfronthosting.co.za> |
2011-03-29 19:28:41 | terry.reedy | link | issue11712 messages |
2011-03-29 19:28:41 | terry.reedy | create | |
|