mirror of
https://github.com/python/cpython.git
synced 2026-04-05 03:21:05 +00:00
Issue #23549: Clarify confusion in heapq doc - accessing the mininmal element
Merge 3.4 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.
This commit is contained in:
commit
a84099bcc5
1 changed files with 4 additions and 2 deletions
|
|
@ -47,7 +47,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)
|
||||
|
|
@ -124,7 +125,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue