11/40
Part 3 of 8 · heapqLearn and do

Stand math.inf in for a missing priority

A priority that's missing, like None for credit that never expires, can't be compared with a number at all:

h = [(30, "promo")]
heapq.heappush(h, (None, "base"))
TypeError: '<' not supported between instances of 'NoneType' and 'int'

Put a value in its place that sorts where you want it. math.inf is larger than every number, so credit that never expires sorts last.

In the editor, soonest_first(credits) takes credits as dicts with an "id" and an "expires" that can be None. Write the one push, with math.inf in place of None, so the credits come back soonest expiry first.