As shown in a basic example in the doc, one can always use a tuple so that the first element is compared as the priority key. However, what if the associated data are not comparable? What would be an elegant way to resolve this?
For example,
import heapq
h = [(3, 2), (4, 3)]
heapq.heapify(h)
heapq.heappush(h, (3, (0, 1)))
This emits
TypeError: unorderable types: tuple() < int()