Primary Queue

We can implement primary queue in python using heapq.

heap = []
heapq.heappush(heap, (priority, value))

Example

heapq.heappush(heap, (1, "apple"))
heapq.heappush(heap, (2, "banana"))
heapq.heappop(heap) # apple

Note: the tuple needs to be unique. So there can't be another (1, "apple") added in.

When using tuple, heapq will compare using the first value