Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 356902d

Browse files
committed
Small code and comment cleanups
1 parent 1f54814 commit 356902d

1 file changed

Lines changed: 4 additions & 14 deletions

File tree

Lib/heapq.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ def heappop(heap):
141141
returnitem = heap[0]
142142
heap[0] = lastelt
143143
_siftup(heap, 0)
144-
else:
145-
returnitem = lastelt
146-
return returnitem
144+
return returnitem
145+
return lastelt
147146

148147
def heapreplace(heap, item):
149148
"""Pop and return the current smallest value, and add the new item.
@@ -357,14 +356,14 @@ def merge(*iterables):
357356
# Algorithm notes for nlargest() and nsmallest()
358357
# ==============================================
359358
#
360-
# Makes just a single pass over the data while keeping the k most extreme values
359+
# Make a single pass over the data while keeping the k most extreme values
361360
# in a heap. Memory consumption is limited to keeping k values in a list.
362361
#
363362
# Measured performance for random inputs:
364363
#
365364
# number of comparisons
366365
# n inputs k-extreme values (average of 5 trials) % more than min()
367-
# ------------- ---------------- - ------------------- -----------------
366+
# ------------- ---------------- --------------------- -----------------
368367
# 1,000 100 3,317 133.2%
369368
# 10,000 100 14,046 40.5%
370369
# 100,000 100 105,749 5.7%
@@ -542,15 +541,6 @@ def nlargest(n, iterable, key=None):
542541

543542

544543
if __name__ == "__main__":
545-
# Simple sanity test
546-
heap = []
547-
data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
548-
for item in data:
549-
heappush(heap, item)
550-
sort = []
551-
while heap:
552-
sort.append(heappop(heap))
553-
print(sort)
554544

555545
import doctest
556546
doctest.testmod()

0 commit comments

Comments
 (0)