In the Python docs,
The lowest valued entries are retrieved first (the lowest valued entry is the one returned by
sorted(list(entries))[0]). A typical pattern for entries is a tuple in the form:(priority_number, data).
It appears the queue will be sorted by priority then data, which may not be always correct. Suppose data “item 2”, is enqueued before “item 1”, item 1 will still go first. In another docs page, heapq, it suggests the use of a counter. So I will store my data like entry = [priority, count, task]. Isn’t there something like
PriorityQueue.put(item, priority)
Then I won’t need to implement the ordering myself?
As far as I know, what you’re looking for isn’t available out of the box. Anyway, note that it wouldn’t be hard to implement:
Example output: