25 Jun
2002
25 Jun
'02
3:33 p.m.
Gustavo Niemeyer wrote:
If priority queues were to be included, I'd rather add the necessary support in Queue to easily attach priority handling, if that's not already possible.
it takes a whopping four lines of code, if you're a pragmatic programmer: # # implementation import Queue, bisect class PriorityQueue(Queue.Queue): def _put(self, item): bisect.insort(self.queue, item) # # usage queue = PriorityQueue(0) queue.put((2, "second")) queue.put((1, "first")) queue.put((3, "third")) priority, value = queue.get() </F>