summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libheapq.tex
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-12-02 08:59:14 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-12-02 08:59:14 (GMT)
commit4901a1f267e9d632f85054ce8b21ff23bff305e1 (patch)
tree27fdb176c85c194cc32d9a72d4812860bd2c4fb6 /Doc/lib/libheapq.tex
parentde7b99045d6ee40c2f6b0abbf9d1b5345d9cf15e (diff)
downloadcpython-4901a1f267e9d632f85054ce8b21ff23bff305e1.zip
cpython-4901a1f267e9d632f85054ce8b21ff23bff305e1.tar.gz
cpython-4901a1f267e9d632f85054ce8b21ff23bff305e1.tar.bz2
Add key= argument to heapq.nsmallest() and heapq.nlargest().
Diffstat (limited to 'Doc/lib/libheapq.tex')
-rw-r--r--Doc/lib/libheapq.tex20
1 files changed, 14 insertions, 6 deletions
diff --git a/Doc/lib/libheapq.tex b/Doc/lib/libheapq.tex
index 55ef641..eaf7051 100644
--- a/Doc/lib/libheapq.tex
+++ b/Doc/lib/libheapq.tex
@@ -90,16 +90,24 @@ True
The module also offers two general purpose functions based on heaps.
-\begin{funcdesc}{nlargest}{n, iterable}
+\begin{funcdesc}{nlargest}{n, iterable\optional{, key}}
Return a list with the \var{n} largest elements from the dataset defined
-by \var{iterable}. Equivalent to: \code{sorted(iterable, reverse=True)[:n]}
-\versionadded{2.4}
+by \var{iterable}. \var{key}, if provided, specifies a function of one
+argument that is used to extract a comparison key from each element
+in the iterable: \samp{\var{key}=\function{str.lower}}
+Equivalent to: \samp{sorted(iterable, key=key, reverse=True)[:n]}
+\versionadded{2.4}
+\versionchanged[Added the optional \var{key} argument]{2.5}
\end{funcdesc}
-\begin{funcdesc}{nsmallest}{n, iterable}
+\begin{funcdesc}{nsmallest}{n, iterable\optional{, key}}
Return a list with the \var{n} smallest elements from the dataset defined
-by \var{iterable}. Equivalent to: \code{sorted(iterable)[:n]}
-\versionadded{2.4}
+by \var{iterable}. \var{key}, if provided, specifies a function of one
+argument that is used to extract a comparison key from each element
+in the iterable: \samp{\var{key}=\function{str.lower}}
+Equivalent to: \samp{sorted(iterable, key=key)[:n]}
+\versionadded{2.4}
+\versionchanged[Added the optional \var{key} argument]{2.5}
\end{funcdesc}
Both functions perform best for smaller values of \var{n}. For larger