diff options
author | Raymond Hettinger <python@rcn.com> | 2010-10-31 22:36:06 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-10-31 22:36:06 (GMT) |
commit | b9fe800929e3a6b5af8ab0661572af5301492bd0 (patch) | |
tree | 9912c8d60c46ce5f68bcfd8f6f48c688d6d38685 /Doc/glossary.rst | |
parent | 099cfed120d2382ed01b35bbdbdda0ed7a7d163d (diff) | |
download | cpython-b9fe800929e3a6b5af8ab0661572af5301492bd0.zip cpython-b9fe800929e3a6b5af8ab0661572af5301492bd0.tar.gz cpython-b9fe800929e3a6b5af8ab0661572af5301492bd0.tar.bz2 |
Issue #9886: Add a key-function entry to the glossary.
Diffstat (limited to 'Doc/glossary.rst')
-rw-r--r-- | Doc/glossary.rst | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/glossary.rst b/Doc/glossary.rst index e66bf11..dccb9f6 100644 --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -288,6 +288,26 @@ Glossary instances of user-defined classes are hashable by default; they all compare unequal, and their hash value is their :func:`id`. + key function + A key function or collation function is a callable that returns a value + used for sorting or ordering. For example, :func:`locale.strxfrm` is + used to produce a sort key that is aware of locale specific sort + conventions. + + A number of tools in Python accept key functions to control how elements + are ordered or grouped. They include :func:`min`, :func:`max`, + :func:`sorted`, :meth:`list.sort`, :func:`heapq.nsmallest`, + :func:`heapq.nlargest`, and :func:`itertools.groupby`. + + There are several ways to create a key function. For example. the + :meth:`str.lower` method can serve as a key function for case insensitive + sorts. Alternatively, an ad-hoc key function can be built from a + :keyword:`lambda` expression such as ``lambda r: (r[0], r[2])``. Also, + the :mod:`operator` module provides three key function constuctors: + :func:`~operator.attrgetter`, :func:`~operator.itemgetter`, and + :func:`~operator.methodcaller`. See the :ref:`Sorting HOW TO` for + examples of how to create and use key functions. + IDLE An Integrated Development Environment for Python. IDLE is a basic editor and interpreter environment which ships with the standard distribution of |