A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-June/025927.html below:

[Python-Dev] Priority queue (binary heap) python code

[Python-Dev] Priority queue (binary heap) python codeFredrik Lundh fredrik@pythonware.com
Tue, 25 Jun 2002 17:33:55 +0200
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>





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4