diff options
author | Raymond Hettinger <python@rcn.com> | 2010-04-04 18:34:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-04-04 18:34:45 (GMT) |
commit | a551f31d482e9feb61f80fe8cf1d1e615e4e8d50 (patch) | |
tree | 3df429006c8fe7b5474c61c91d148d2f57dc7ff0 /Doc/library/functools.rst | |
parent | fdaaa9c9d8a768c324a49250c91295ebce6b201a (diff) | |
download | cpython-a551f31d482e9feb61f80fe8cf1d1e615e4e8d50.zip cpython-a551f31d482e9feb61f80fe8cf1d1e615e4e8d50.tar.gz cpython-a551f31d482e9feb61f80fe8cf1d1e615e4e8d50.tar.bz2 |
Add functools.CmpToKey()
Diffstat (limited to 'Doc/library/functools.rst')
-rw-r--r-- | Doc/library/functools.rst | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 6dc9f0a..3337ead 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -17,6 +17,28 @@ function for the purposes of this module. The :mod:`functools` module defines the following functions: +.. function:: CmpToKey(func) + + Transform an old-style comparison function to a key-function. Used with + tools that accept key functions (such as :func:`sorted`, :func:`min`, + :func:`max`, :func:`heapq.nlargest`, :func:`heapq.nsmallest`, + :func:`itertools.groupby`). + This function is primarily used as a transition tool for programs + being converted to Py3.x where comparison functions are no longer + supported. + + A compare function is any callable that accept two arguments, compares + them, and returns a negative number for less-than, zero for equality, + or a positive number for greater-than. A key function is a callable + that accepts one argument and returns another value that indicates + the position in the desired collation sequence. + + Example:: + + sorted(iterable, key=CmpToKey(locale.strcoll)) # locale-aware sort order + + .. versionadded:: 2.7 + .. function:: total_ordering(cls) Given a class defining one or more rich comparison ordering methods, this |