summaryrefslogtreecommitdiffstats
path: root/Doc/library/heapq.rst
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2015-03-15 03:20:36 (GMT)
committerEli Bendersky <eliben@gmail.com>2015-03-15 03:20:36 (GMT)
commit9872ad46d5c8b91caba942e87d9fe6d00843a518 (patch)
treecddc77f3cada63670bc123b6d578eb794b21dc11 /Doc/library/heapq.rst
parent251aede2f23f13b33dc4fc28bb18a5f416fad345 (diff)
downloadcpython-9872ad46d5c8b91caba942e87d9fe6d00843a518.zip
cpython-9872ad46d5c8b91caba942e87d9fe6d00843a518.tar.gz
cpython-9872ad46d5c8b91caba942e87d9fe6d00843a518.tar.bz2
Issue #23549: Clarify confusion in heapq doc - accessing the mininmal element
The current documentation only mentions heap[0] as the smallest element in the beginning, and not in any of the methods' docs. There's no method to access the minimal element without popping it, and the documentation of nsmallest is confusing because it may suggest that min() is the way to go for n==1. default
Diffstat (limited to 'Doc/library/heapq.rst')
-rw-r--r--Doc/library/heapq.rst6
1 files changed, 4 insertions, 2 deletions
diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst
index cfc6296..a7d1f45 100644
--- a/Doc/library/heapq.rst
+++ b/Doc/library/heapq.rst
@@ -49,7 +49,8 @@ The following functions are provided:
.. function:: heappop(heap)
Pop and return the smallest item from the *heap*, maintaining the heap
- invariant. If the heap is empty, :exc:`IndexError` is raised.
+ invariant. If the heap is empty, :exc:`IndexError` is raised. To access the
+ smallest item without popping it, use ``heap[0]``.
.. function:: heappushpop(heap, item)
@@ -125,7 +126,8 @@ The module also offers three general purpose functions based on heaps.
The latter two functions perform best for smaller values of *n*. For larger
values, it is more efficient to use the :func:`sorted` function. Also, when
``n==1``, it is more efficient to use the built-in :func:`min` and :func:`max`
-functions.
+functions. If repeated usage of these functions is required, consider turning
+the iterable into an actual heap.
Basic Examples