summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-05-30 09:28:36 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-05-30 09:28:36 (GMT)
commit35db43955cf231a4040d32c77b1ff5a4b639039f (patch)
tree670f590844d11613b16ab61b018caaeb93e9bab1 /Doc
parente7bfe13635e4201660c9d016b62de10c2f7c9de3 (diff)
downloadcpython-35db43955cf231a4040d32c77b1ff5a4b639039f.zip
cpython-35db43955cf231a4040d32c77b1ff5a4b639039f.tar.gz
cpython-35db43955cf231a4040d32c77b1ff5a4b639039f.tar.bz2
Issue #13742: Add key and reverse parameters to heapq.merge()
Diffstat (limited to 'Doc')
-rw-r--r--Doc/glossary.rst7
-rw-r--r--Doc/library/heapq.rst14
2 files changed, 17 insertions, 4 deletions
diff --git a/Doc/glossary.rst b/Doc/glossary.rst
index f71a1f7..08ee9db 100644
--- a/Doc/glossary.rst
+++ b/Doc/glossary.rst
@@ -444,12 +444,13 @@ Glossary
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`.
+ :func:`sorted`, :meth:`list.sort`, :func:`heapq.merge`,
+ :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
+ sorts. Alternatively, a 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 constructors:
:func:`~operator.attrgetter`, :func:`~operator.itemgetter`, and
diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst
index 4f1a682..2a41434 100644
--- a/Doc/library/heapq.rst
+++ b/Doc/library/heapq.rst
@@ -81,7 +81,7 @@ The following functions are provided:
The module also offers three general purpose functions based on heaps.
-.. function:: merge(*iterables)
+.. function:: merge(*iterables, key=None, reverse=False)
Merge multiple sorted inputs into a single sorted output (for example, merge
timestamped entries from multiple log files). Returns an :term:`iterator`
@@ -91,6 +91,18 @@ The module also offers three general purpose functions based on heaps.
not pull the data into memory all at once, and assumes that each of the input
streams is already sorted (smallest to largest).
+ Has two optional arguments which must be specified as keyword arguments.
+
+ *key* specifies a :term:`key function` of one argument that is used to
+ extract a comparison key from each input element. The default value is
+ ``None`` (compare the elements directly).
+
+ *reverse* is a boolean value. If set to ``True``, then the input elements
+ are merged as if each comparison were reversed.
+
+ .. versionchanged:: 3.5
+ Added the optional *key* and *reverse* parameters.
+
.. function:: nlargest(n, iterable, key=None)