from the documentation for Queue.py
There actually a PriorityQueue that automatically sort the elements in queue, but usually the elements are tuple structure (priority number, data)
I wrote some sample code here, it Q._pop() the tuple with smallest priority number:
import Queue
q = Queue.PriorityQueue()
print type(q)
print(q.queue)
q._put((4,'f'))
q._put((1,'c'))
q._put((5, 'a'))
q._put((10, 'b'))
q._put((6, 'd'))
print(q.queue)
q._get()
print(q.queue)
q._put((2,'f'))
print(q.queue)
The output is:
<type 'instance'>
[]
[(1, 'c'), (4, 'f'), (5, 'a'), (10, 'b'), (6, 'd')]
[(4, 'f'), (6, 'd'), (5, 'a'), (10, 'b')]
[(2, 'f'), (4, 'f'), (5, 'a'), (10, 'b'), (6, 'd')]
One thing I notice is that for the first time we print the q.queue, before we do any _get(), it doesn't show ordered queue, but once we call _get(), it always gives ordered queue.
PriorityQueueequivalent with the sorting logic you describe.PriorityQueue, as you point out, sorts by the first argument, and the docs indicate no way to change that.