-
-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python 3 preparation: cmp parameter of sorted() function and L.sort() method are gone #16536
Comments
Demonstrate behavior of cmp= and key= in Py2 and Py3 |
comment:1
Attachment: exercise-cmp-key-parameters.py.gz The workings of This is also demonstrated in the attached script. It is also shown that it is not a good idea the use "cmp=" and "key=" together even in Py2! |
Dependencies: #16853 |
comment:7
see #21035 for a step in that direction |
comment:9
This is now mostly done. In some places, cmp was only deprecated. |
comment:12
another step in #23698 |
comment:14
Maybe we could now close this one ? |
comment:15
ping ? any objection to close as invalid ? |
In Py2 the standard function sorted() and the mutable list method sort() both have an optional parameter
cmp=
that takes a custom comparison function of two arguments.The parameter is no more available in Py3.
The recommended way is to use the
key=
which specifies a function of one argument that is used to extract a comparison key from each list element. This has also better performance.While there is a function functools.cmp_to_key() to convert an old-style cmp function to a key function, it is preferable to directly use an appropriate key function.
This ticket is tracked as a dependency of meta-ticket ticket:15980.
Depends on #16853
Depends on #17200
Depends on #17229
CC: @tscrim @embray @jdemeyer
Component: python3
Issue created by migration from https://trac.sagemath.org/ticket/16536
The text was updated successfully, but these errors were encountered: