0
What is the role of function cmp_to key from funtools module
What is the role of function cmp to key, when this is user often?
3 Respostas
+ 1
* when this is used?
0
I haven't seen any need to use this yet. cmp_to_key is more of a utility tool for Python 2 backwards compatibility.
For sorting or comparing values, python 2 used the concept of comparison functions, that have two input values and return negative, zero or positive number.
Python 3 uses key functions for sorting, these have only a single argument and associates a (sorting) key to each value.
This function cmp_to_key is supposed to bridge this difference.
https://docs.python.org/3.8/library/functools.html
0
Thanks