Issue #13742: Add key and reverse parameters to heapq.merge()

This commit is contained in:
Raymond Hettinger 2014-05-30 02:28:36 -07:00
parent e7bfe13635
commit 35db43955c
5 changed files with 98 additions and 19 deletions

View file

@ -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)