@@ -283,6 +283,26 @@ Glossary
283283 instances of user-defined classes are hashable by default; they all
284284 compare unequal, and their hash value is their :func: `id `.
285285
286+ key function
287+ A key function or collation function is a callable that returns a value
288+ used for sorting or ordering. For example, :func: `locale.strxfrm ` is
289+ used to produce a sort key that is aware of locale specific sort
290+ conventions.
291+
292+ A number of tools in Python accept key functions to control how elements
293+ are ordered or grouped. They include :func: `min `, :func: `max `,
294+ :func: `sorted `, :meth: `list.sort `, :func: `heapq.nsmallest `,
295+ :func: `heapq.nlargest `, and :func: `itertools.groupby `.
296+
297+ There are several ways to create a key function. For example. the
298+ :meth: `str.lower ` method can serve as a key function for case insensitive
299+ sorts. Alternatively, an ad-hoc key function can be built from a
300+ :keyword: `lambda ` expression such as ``lambda r: (r[0], r[2]) ``. Also,
301+ the :mod: `operator ` module provides three key function constuctors:
302+ :func: `~operator.attrgetter `, :func: `~operator.itemgetter `, and
303+ :func: `~operator.methodcaller `. See the :ref: `Sorting HOW TO ` for
304+ examples of how to create and use key functions.
305+
286306 IDLE
287307 An Integrated Development Environment for Python. IDLE is a basic editor
288308 and interpreter environment which ships with the standard distribution of
0 commit comments