473,396 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

bisect and Queue modules in Python 2.4

Dear All,

Python 2.4 (#1, Mar 22 2005, 21:42:42)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import Queue
q=Queue.Queue()
type(q.queue) <type 'collections.deque'>


q.queue used to be a list, and now it is something else?

I was using bisect module to implement min priority queue, as described
in python library reference (see
http://www.python.org/doc/2.3.5/lib/...-example.html). I have found
out that in Python 2.4 q.queue does not support "insert" anymore, which
breaks bisect. Please help!

Thank you,
Semen
Mar 16 '06 #1
2 2553
SA Trygubenko wrote:
q.queue used to be a list, and now it is something else?

I was using bisect module to implement min priority queue, as described
in python library reference (see
http://www.python.org/doc/2.3.5/lib/...-example.html). I have found
out that in Python 2.4 q.queue does not support "insert" anymore, which
breaks bisect. Please help!


class PriorityQueue(Queue.Queue):
def _put(self, item):
bisect.insort(self.queue, item)
def _init(self, maxsize):
self.maxsize = maxsize
self.queue = []
def _get(self):
return self.queue.pop(0)

or somesuch might work.

Peter
Mar 16 '06 #2
Peter Otten <__*******@web.de> wrote:
SA Trygubenko wrote:
q.queue used to be a list, and now it is something else?

I was using bisect module to implement min priority queue, as described
in python library reference (see
http://www.python.org/doc/2.3.5/lib/...-example.html). I have found
out that in Python 2.4 q.queue does not support "insert" anymore, which
breaks bisect. Please help!


class PriorityQueue(Queue.Queue):
def _put(self, item):
bisect.insort(self.queue, item)
def _init(self, maxsize):
self.maxsize = maxsize
self.queue = []
def _get(self):
return self.queue.pop(0)

or somesuch might work.


Yep, it should, but using heapq instead of bisect is, I suspect, way
better -- there's a recipe on the Cookbook for that (Queue+heapq), and
though I (of course;-) prefer the version as edited for the printed
(2nd) edition, the online one can also no doubt be useful.
Alex
Mar 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gary Robinson | last post by:
I'm wondering if bisect.insort is guaranteed to use a __cmp__ method, for now and for future python versions, if it exists, for the items being inserted? That would be good to know because then...
0
by: cognizor | last post by:
As a Python, not a C user, I'd chime in on behalf of non-developers especially to say Yes, please keep the python versions of std library modules. They are much used. In pro: The python...
17
by: Bart Nessux | last post by:
How can one view the contents of a queue? I'd like to verify that the queue has the same number of objects as the list that has been put into it. Also, should one think of a queue as static or...
0
by: Nick Coghlan | last post by:
Anyone playing with the CPython interpreter's new command line switch might have noticed that it only works with top-level modules (i.e. scripts that are directly on sys.path). If the script is...
9
by: phil | last post by:
And sorry I got ticked, frustrating week >And I could help more, being fairly experienced with >threading issues and race conditions and such, but >as I tried to indicate in the first place,...
15
by: Nick Coghlan | last post by:
Python 2.4's -m command line switch only works for modules directly on sys.path. Trying to use it with modules inside packages will fail with a "Module not found" error. This PEP aims to fix that...
9
by: Paulo da Silva | last post by:
Hi! What is the best way to have something like the bisect_left method on a list of lists being the comparision based on an specified arbitrary i_th element of each list element? Is there,...
3
by: Chris Lasher | last post by:
Hello, I am working with large graphs (~150,000 to 500,000 nodes) which I need decompose node-by-node, in order of a node's value. A node's value is determined by the sum of its edge weights....
0
by: Robert Bossy | last post by:
Hi, I stumbled into a sorted list intersection algorithm by Baeza-Yates which I found quite elegant. For the lucky enough to have a springerlink access, here's the citation:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.