I have a simple heap defined as a list of lists. I was using heapop from the heapq module to extract the list with the smallest key (which I learnt is implicitly the first element of the inner list). But in the following case, the pop operation seems to be giving unusual results.
Can someone explain why?
heap=[[0, 0, 0], [inf, 1, 1], [inf, 2, 2], [5, 3, 3], [inf, 4, 4]]
heapq.heappop(heap)
[0, 0, 0]
heapq.heappop(heap)
[inf, 1, 1]
heapq.heappop(heap)
[5, 3, 3]
heapq.heappop(heap)
[inf, 2, 2]
heapq.heappop(heap)
[inf, 4, 4]