mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Simplify heapreplace() -- there's no need for an explicit test for
empty heap, since heap[0] raises the appropriate IndexError already.
This commit is contained in:
parent
b2865919cc
commit
3c8dd0c6e7
1 changed files with 4 additions and 7 deletions
11
Lib/heapq.py
11
Lib/heapq.py
|
|
@ -150,13 +150,10 @@ def heapreplace(heap, item):
|
|||
returned may be larger than item! That constrains reasonable uses of
|
||||
this routine.
|
||||
"""
|
||||
|
||||
if heap:
|
||||
returnitem = heap[0]
|
||||
heap[0] = item
|
||||
_siftup(heap, 0)
|
||||
return returnitem
|
||||
heap.pop() # raise IndexError
|
||||
returnitem = heap[0] # raises appropriate IndexError if heap is empty
|
||||
heap[0] = item
|
||||
_siftup(heap, 0)
|
||||
return returnitem
|
||||
|
||||
def heapify(x):
|
||||
"""Transform list into a heap, in-place, in O(len(heap)) time."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue