[Tutor] Linked List

John Fouhy jfouhy at paradise.net.nz
Sun Mar 6 19:07:45 CET 2005


Jeff Shannon wrote:
> You might want to check the Cookbook to see if there's a priority
> queue recipe there.  If not, I suspect that Google can be convinced to
> yield something...

 From the bisect module docs:

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()

-- 
John.


More information about the Tutor mailing list