Commit ccae479e authored by Raymond Hettinger's avatar Raymond Hettinger

Issue 22830: Clarify docs for functools.cmp_to_key().

parent fb136d19
...@@ -22,8 +22,8 @@ The :mod:`functools` module defines the following functions: ...@@ -22,8 +22,8 @@ The :mod:`functools` module defines the following functions:
.. function:: cmp_to_key(func) .. function:: cmp_to_key(func)
Transform an old-style comparison function to a key function. Used with Transform an old-style comparison function to a :term:`key function`. Used
tools that accept key functions (such as :func:`sorted`, :func:`min`, with tools that accept key functions (such as :func:`sorted`, :func:`min`,
:func:`max`, :func:`heapq.nlargest`, :func:`heapq.nsmallest`, :func:`max`, :func:`heapq.nlargest`, :func:`heapq.nsmallest`,
:func:`itertools.groupby`). This function is primarily used as a transition :func:`itertools.groupby`). This function is primarily used as a transition
tool for programs being converted to Python 3 where comparison functions are tool for programs being converted to Python 3 where comparison functions are
...@@ -32,13 +32,16 @@ The :mod:`functools` module defines the following functions: ...@@ -32,13 +32,16 @@ The :mod:`functools` module defines the following functions:
A comparison function is any callable that accept two arguments, compares them, A comparison function is any callable that accept two arguments, compares them,
and returns a negative number for less-than, zero for equality, or a positive 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 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 argument and returns another value to be used as the sort key.
collation sequence.
Example:: Example::
sorted(iterable, key=cmp_to_key(locale.strcoll)) # locale-aware sort order sorted(iterable, key=cmp_to_key(locale.strcoll)) # locale-aware sort order
For sorting examples and a brief sorting tutorial, see `Sorting HowTo
<https://wiki.python.org/moin/HowTo/Sorting/>`_\.
.. versionadded:: 2.7 .. versionadded:: 2.7
.. function:: total_ordering(cls) .. function:: total_ordering(cls)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment