summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-07 18:58:11 (GMT)
committerGuido van Rossum <guido@python.org>2002-08-07 18:58:11 (GMT)
commit3c8dd0c6e783b2a07017d0fdf7f60232603ed407 (patch)
treedf4f18d7efd6a70c24be1166155278398a31bd8a /Lib
parentb2865919cc150d3cf682d06ccc99d8de285b1de3 (diff)
downloadcpython-3c8dd0c6e783b2a07017d0fdf7f60232603ed407.zip
cpython-3c8dd0c6e783b2a07017d0fdf7f60232603ed407.tar.gz
cpython-3c8dd0c6e783b2a07017d0fdf7f60232603ed407.tar.bz2
Simplify heapreplace() -- there's no need for an explicit test for
empty heap, since heap[0] raises the appropriate IndexError already.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/heapq.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/Lib/heapq.py b/Lib/heapq.py
index 47326f3..4970437 100644
--- a/Lib/heapq.py
+++ b/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."""