This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author scooter4j
Recipients docs@python, scooter4j
Date 2017-11-26.16:05:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1511712348.11.0.213398074469.issue32142@psf.upfronthosting.co.za>
In-reply-to
Content
The documentation for heapq.heappop(heap) says:
"Pop and return the smallest item from the heap, maintaining the heap invariant. If the heap is empty, IndexError is raised. To access the smallest item without popping it, use heap[0]."

yet, in the following code, the resultant heap doesn't reflect the heap invariant:

import heapq
li = [5, 7, 9, 1, 4, 3]
heapq.heapify(li)
#change a couple values in the heap
li[3] = 16
li[4] = 2
print (heapq.heappop(li))
print ("The heap after pop is : ",end="")
print (list(li))

This prints: The heap after pop is : [3, 4, 9, 16, 2]

The documentation implies to me that heapify would be called internally after heappop, but I may be misreading. Perhaps heappop could say that the heap invariant is maintained if the heap is properly sorted before the heappop invocation.
History
Date User Action Args
2017-11-26 16:05:48scooter4jsetrecipients: + scooter4j, docs@python
2017-11-26 16:05:48scooter4jsetmessageid: <1511712348.11.0.213398074469.issue32142@psf.upfronthosting.co.za>
2017-11-26 16:05:48scooter4jlinkissue32142 messages
2017-11-26 16:05:47scooter4jcreate