I'm trying to use the Python module heapq
in my program but I ran into a strange problem using heapq.heappop()
. The function does not appear to return the smallest element in the heap. Take a look at the following code:
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import heapq
>>> list = [[1326, 'a'], [654, 'b']]
>>> print heapq.heappop(list)
[1326, 'a']
>>> print heapq.heappop(list)
[654, 'b']
Should heappop()
not return [654, 'b']
first and then [1326, 'a']
?