summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-04-04 21:45:01 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-04-04 21:45:01 (GMT)
commitbb006cf26cc41aefcddc8f06722c524826aacefa (patch)
tree5d0e82402052f188ea868cf94497eba52a7b38fd /Doc
parent4f185228b084ee45ef822198762154457dc343db (diff)
downloadcpython-bb006cf26cc41aefcddc8f06722c524826aacefa.zip
cpython-bb006cf26cc41aefcddc8f06722c524826aacefa.tar.gz
cpython-bb006cf26cc41aefcddc8f06722c524826aacefa.tar.bz2
Add tests for cmp_to_key.
Adopt PEP 8 compliant function name. Factor-out existing uses cmp_to_key. Update documentation to use internal pointers instead of external resource.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/functions.rst5
-rw-r--r--Doc/library/functools.rst4
-rw-r--r--Doc/library/stdtypes.rst3
3 files changed, 6 insertions, 6 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 0f45319..cfb1945 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -1154,9 +1154,8 @@ available. They are listed here in alphabetical order.
In general, the *key* and *reverse* conversion processes are much faster
than specifying an equivalent *cmp* function. This is because *cmp* is
called multiple times for each list element while *key* and *reverse* touch
- each element only once. To convert an old-style *cmp* function to a *key*
- function, see the `CmpToKey recipe in the ASPN cookbook
- <http://code.activestate.com/recipes/576653/>`_\.
+ each element only once. Use :func:`functools.cmp_to_key` to convert an
+ old-style *cmp* function to a *key* function.
For sorting examples and a brief sorting tutorial, see `Sorting HowTo
<http://wiki.python.org/moin/HowTo/Sorting/>`_\.
diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst
index 3337ead..15c4a95 100644
--- a/Doc/library/functools.rst
+++ b/Doc/library/functools.rst
@@ -17,7 +17,7 @@ function for the purposes of this module.
The :mod:`functools` module defines the following functions:
-.. function:: CmpToKey(func)
+.. function:: cmp_to_key(func)
Transform an old-style comparison function to a key-function. Used with
tools that accept key functions (such as :func:`sorted`, :func:`min`,
@@ -35,7 +35,7 @@ The :mod:`functools` module defines the following functions:
Example::
- sorted(iterable, key=CmpToKey(locale.strcoll)) # locale-aware sort order
+ sorted(iterable, key=cmp_to_key(locale.strcoll)) # locale-aware sort order
.. versionadded:: 2.7
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index 3307685..0a6178b 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -1618,7 +1618,8 @@ Notes:
In general, the *key* and *reverse* conversion processes are much faster than
specifying an equivalent *cmp* function. This is because *cmp* is called
multiple times for each list element while *key* and *reverse* touch each
- element only once.
+ element only once. Use :func:`functools.cmp_to_key` to convert an
+ old-style *cmp* function to a *key* function.
.. versionchanged:: 2.3
Support for ``None`` as an equivalent to omitting *cmp* was added.