[issue32142] heapq.heappop - documentation misleading or doesn't work

Eric V. Smith report at bugs.python.org
Sun Nov 26 11:24:10 EST 2017


Eric V. Smith <eric at trueblade.com> added the comment:

The heap invariant is also required in order to even meet the documented behavior of returning the smallest item.

>>> import heapq
>>> li = [5, 7, 9, 1, 4, 3]
>>> heapq.heapify(li)
>>> li
[1, 4, 3, 7, 5, 9]
>>> li[2] = 0
>>> heapq.heappop(li)
1
>>> li
[0, 4, 9, 7, 5]
>>>

I guess the argument could be made that docs say "from the heap", and by modifying the list yourself it's no longer a heap.

----------
nosy: +eric.smith

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32142>
_______________________________________


More information about the Python-bugs-list mailing list