Hi all.
What is the official way of peeking in a python heap as created by the heapq libs? Right now I have
def heappeak(heap):
smallest = heappop(heap)
heappush(heap, smallest)
return smallest
which is arguably, not very nice. Can I always assume that heap[0]
is the top of the heap and use that? Or would that assume too much of the underlying implementation?