mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Improve the documented advice on how to best use heapq.heapreplace().
This commit is contained in:
parent
1761a7cc8b
commit
28224f897a
3 changed files with 10 additions and 3 deletions
|
@ -59,7 +59,11 @@ If the heap is empty, \exception{IndexError} is raised.
|
|||
This is more efficient than \function{heappop()} followed
|
||||
by \function{heappush()}, and can be more appropriate when using
|
||||
a fixed-size heap. Note that the value returned may be larger
|
||||
than \var{item}! That constrains reasonable uses of this routine.
|
||||
than \var{item}! That constrains reasonable uses of this routine
|
||||
unless written as part of a larger expression:
|
||||
\begin{verbatim}
|
||||
result = item <= heap[0] and item or heapreplace(heap, item)
|
||||
\end{verbatim}
|
||||
\end{funcdesc}
|
||||
|
||||
Example of use:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue