How to access the top element in heapq without deleting (popping) it python ?
I need only to check the element at the top of my heapq without popping it. How can I do that.
How to access the top element in heapq without deleting (popping) it python?
10.4k views Asked by ibra At
1
From docs python, under heapq.heappop definition, it says:
To access the smallest item without popping it, use heap[0].
It says smallest, because it is a min heap. So the item at the top will be the smallest one.
Illustration:
Result: