A simple example for the usage of the python heap implementation is
from heapq import heappush, heappop
heap = []
data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
for item in data:
heappush(heap, item)
In a more complicated scenario, I have an array of tuples like
tuples = [(5,"foo",True),(2,"bar", False),(8,"foobar",True)]
and want to use the first entry of each tuple as heap key, i.e. the tuples should be sorted according to the number in the tuples.
How can I do that?