More information can be found in :ref:`typeiter`.
+ 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
+ <sortinghowto>` for examples of how to create and use key functions.
+
keyword argument
Arguments which are preceded with a ``variable_name=`` in the call.
The variable name designates the local name in the function to which the
: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-howto` for
+ :func:`~operator.methodcaller`. See the :ref:`sortinghowto` for
examples of how to create and use key functions.
lambda
.. data:: feature_namespaces
- Value: ``"http://xml.org/sax/features/namespaces"`` --- true: Perform Namespace
- processing. --- false: Optionally do not perform Namespace processing (implies
- namespace-prefixes; default). --- access: (parsing) read-only; (not parsing)
- read/write
+ | value: ``"http://xml.org/sax/features/namespaces"``
+ | true: Perform Namespace processing.
+ | false: Optionally do not perform Namespace processing (implies
+ namespace-prefixes; default).
+ | access: (parsing) read-only; (not parsing) read/write
.. data:: feature_namespace_prefixes
- Value: ``"http://xml.org/sax/features/namespace-prefixes"`` --- true: Report
- the original prefixed names and attributes used for Namespace
- declarations. --- false: Do not report attributes used for Namespace
- declarations, and optionally do not report original prefixed names
- (default). --- access: (parsing) read-only; (not parsing) read/write
+ | value: ``"http://xml.org/sax/features/namespace-prefixes"``
+ | true: Report the original prefixed names and attributes used for Namespace
+ declarations.
+ | false: Do not report attributes used for Namespace declarations, and
+ optionally do not report original prefixed names (default).
+ | access: (parsing) read-only; (not parsing) read/write
.. data:: feature_string_interning
- Value: ``"http://xml.org/sax/features/string-interning"`` --- true: All element
- names, prefixes, attribute names, Namespace URIs, and local names are interned
- using the built-in intern function. --- false: Names are not necessarily
- interned, although they may be (default). --- access: (parsing) read-only; (not
- parsing) read/write
+ | value: ``"http://xml.org/sax/features/string-interning"``
+ | true: All element names, prefixes, attribute names, Namespace URIs, and
+ local names are interned using the built-in intern function.
+ | false: Names are not necessarily interned, although they may be (default).
+ | access: (parsing) read-only; (not parsing) read/write
.. data:: feature_validation
- Value: ``"http://xml.org/sax/features/validation"`` --- true: Report all
- validation errors (implies external-general-entities and
- external-parameter-entities). --- false: Do not report validation errors. ---
- access: (parsing) read-only; (not parsing) read/write
+ | value: ``"http://xml.org/sax/features/validation"``
+ | true: Report all validation errors (implies external-general-entities and
+ external-parameter-entities).
+ | false: Do not report validation errors.
+ | access: (parsing) read-only; (not parsing) read/write
.. data:: feature_external_ges
- Value: ``"http://xml.org/sax/features/external-general-entities"`` --- true:
- Include all external general (text) entities. --- false: Do not include
- external general entities. --- access: (parsing) read-only; (not parsing)
- read/write
+ | value: ``"http://xml.org/sax/features/external-general-entities"``
+ | true: Include all external general (text) entities.
+ | false: Do not include external general entities.
+ | access: (parsing) read-only; (not parsing) read/write
.. data:: feature_external_pes
- Value: ``"http://xml.org/sax/features/external-parameter-entities"`` --- true:
- Include all external parameter entities, including the external DTD subset. ---
- false: Do not include any external parameter entities, even the external DTD
- subset. --- access: (parsing) read-only; (not parsing) read/write
+ | value: ``"http://xml.org/sax/features/external-parameter-entities"``
+ | true: Include all external parameter entities, including the external DTD
+ subset.
+ | false: Do not include any external parameter entities, even the external
+ DTD subset.
+ | access: (parsing) read-only; (not parsing) read/write
.. data:: all_features
.. data:: property_lexical_handler
- Value: ``"http://xml.org/sax/properties/lexical-handler"`` --- data type:
- xml.sax.sax2lib.LexicalHandler (not supported in Python 2) --- description: An
- optional extension handler for lexical events like comments. --- access:
- read/write
+ | value: ``"http://xml.org/sax/properties/lexical-handler"``
+ | data type: xml.sax.sax2lib.LexicalHandler (not supported in Python 2)
+ | description: An optional extension handler for lexical events like
+ comments.
+ | access: read/write
.. data:: property_declaration_handler
- Value: ``"http://xml.org/sax/properties/declaration-handler"`` --- data type:
- xml.sax.sax2lib.DeclHandler (not supported in Python 2) --- description: An
- optional extension handler for DTD-related events other than notations and
- unparsed entities. --- access: read/write
+ | value: ``"http://xml.org/sax/properties/declaration-handler"``
+ | data type: xml.sax.sax2lib.DeclHandler (not supported in Python 2)
+ | description: An optional extension handler for DTD-related events other
+ than notations and unparsed entities.
+ | access: read/write
.. data:: property_dom_node
- Value: ``"http://xml.org/sax/properties/dom-node"`` --- data type:
- org.w3c.dom.Node (not supported in Python 2) --- description: When parsing,
- the current DOM node being visited if this is a DOM iterator; when not parsing,
- the root DOM node for iteration. --- access: (parsing) read-only; (not parsing)
- read/write
+ | value: ``"http://xml.org/sax/properties/dom-node"``
+ | data type: org.w3c.dom.Node (not supported in Python 2)
+ | description: When parsing, the current DOM node being visited if this is
+ a DOM iterator; when not parsing, the root DOM node for iteration.
+ | access: (parsing) read-only; (not parsing) read/write
.. data:: property_xml_string
- Value: ``"http://xml.org/sax/properties/xml-string"`` --- data type: String ---
- description: The literal string of characters that was the source for the
- current event. --- access: read-only
+ | value: ``"http://xml.org/sax/properties/xml-string"``
+ | data type: String
+ | description: The literal string of characters that was the source for the
+ current event.
+ | access: read-only
.. data:: all_properties