mirror of https://github.com/python/cpython
Merged revisions 83872 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83872 | benjamin.peterson | 2010-08-08 21:13:10 -0500 (Sun, 08 Aug 2010) | 1 line use 3 space indents ........
This commit is contained in:
parent
a03ff6d3cd
commit
d74ca12fdd
|
@ -19,23 +19,22 @@ 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 key-function. Used with
|
||||||
tools that accept key functions (such as :func:`sorted`, :func:`min`,
|
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`).
|
:func:`itertools.groupby`). This function is primarily used as a transition
|
||||||
This function is primarily used as a transition tool for programs
|
tool for programs being converted to Py3.x where comparison functions are no
|
||||||
being converted to Py3.x where comparison functions are no longer
|
longer supported.
|
||||||
supported.
|
|
||||||
|
|
||||||
A compare function is any callable that accept two arguments, compares
|
A compare function is any callable that accept two arguments, compares them,
|
||||||
them, and returns a negative number for less-than, zero for equality,
|
and returns a negative number for less-than, zero for equality, or a positive
|
||||||
or a positive number for greater-than. A key function is a callable
|
number for greater-than. A key function is a callable that accepts one
|
||||||
that accepts one argument and returns another value that indicates
|
argument and returns another value that indicates the position in the desired
|
||||||
the position in the desired collation sequence.
|
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
|
||||||
|
|
||||||
.. versionadded:: 2.7
|
.. versionadded:: 2.7
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue