473,696 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.de que'>


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 2564
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(Q ueue.Queue):
def _put(self, item):
bisect.insort(s elf.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(Q ueue.Queue):
def _put(self, item):
bisect.insort(s elf.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
1469
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 you don't have to define __lt__ etc. if all you care about is being able to use bisect.insort. If true, I suggest that it might be good to mention the bisect library docs. In any case, if there is a clear answer to my question I'd appreciate...
0
954
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 implementations are legible. They can be followed step by step in the interpreter, with added printout statements, that amazing debug, to understand What the commands do and what else they could do or not do. It's not always
17
2257
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 dynamic (on the put side)? Do you put stuff in it once and then get from it until it's empty or do you put stuff in it a bit at a time? Or, can you do both? Also, does the queue actually get smaller as the threads feed from it or does it stay the...
0
1956
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 inside a package, the invocation will fail with a "Module not found" error. This PEP is aimed at fixing that :) Cheers, Nick.
9
2778
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, you've >provided next to no useful (IMHO) information to >let anyone help you more than this This is about 5% of the code. Uses no locks.
15
2602
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 for Python 2.5. Previously, posting of a draft version of the PEP to python-dev and python-list didn't actually generate any responses. I'm not sure if that's an indication that people don't see the restriction to top-level modules as a problem...
9
4954
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, for lists, something equivalent to the __cmp__ function for classes? Thanks.
3
4358
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. When a node is removed from the graph, its neighbors' values must be updated to take into account the removed edges. I was told to look for a priority queue in Python. I had a look at the heapq module. It looks like it supports ordering on...
0
1208
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: http://dblp.uni-trier.de/rec/bibtex/conf/cpm/Baeza-Yates04 I implemented this algorithm in python and I thought I could share it. I've done some tests and, of course, it can't compete against dict/set intersection, but it will perform pretty well. Computing union...
0
8597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9145
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8880
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8853
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7703
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4611
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3033
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.