When I use heapq.heappop(queue), the first item on the list is popped, but the remaining list is modified. How can I prevent this? (note tuples containing 'r' and 'o' below)
This is my debug output:
Queue: PQ:[(1, 2, 'z'), (1, 3, 't'), (2, 4, 'r'), (2, 5, 'o'), (2, 6, 'f')]
Queue Before Pop: [(1, 2, 'z'), (1, 3, 't'), (2, 4, 'r'), (2, 5, 'o'), (2, 6, 'f')]
priority, counter, node = heapq.heappop(queue)
item returned: (1, 2, 'z') Queue After Pop: [(1, 3, 't'), (2, 5, 'o'), (2, 4, 'r'), (2, 6, 'f')]
The counter is supposed to make sure earlier additions of a node go closer to queue[0].
My queue after pop doesn't just pop heap[0], it rearranges and puts tuple containing 'o' before tuple containing 'r'. Their priority is the same (2), but their counter is 5 and 4 respectively, therefore, they are rearranged in the wrong order.
Inst heappop() only suppose to return heap[0] and move everything else up in the queue? How can I prevent this rearranging?