473,324 Members | 2,248 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,324 software developers and data experts.

data structures module

I am fairly new to Python.
Today, I wanted a priority queue.
I notice that Python does not have any sorted lists.
I know that I can call list.sort(), but that seems rather inefficient
to call every time an element is added.
I am wondering why there is not a module or modules containing many
common data structures. Has such a thing been decided against? Is it
that just nobody has done it? Has nobody else suggested the need for
it? Maybe I should search, but I am too tired now, I need sleep.
Jul 18 '05 #1
5 1397
On 15 Jan 2004 23:06:44 -0800, MetalOne <jc*@iteris.com> wrote:
I am fairly new to Python.
Today, I wanted a priority queue.
I notice that Python does not have any sorted lists.
I know that I can call list.sort(), but that seems rather inefficient
to call every time an element is added.
It is (probably).

Instead, sort the list once, then for each element you insert, find the
place using binary search, then insert the element with insert().
I am wondering why there is not a module or modules containing many
common data structures.
Probably because the native data structures of Python are rich enough to
solve most problems in an adhoc way.
Has such a thing been decided against? Is it


No, but what do you want added that isn't there, and is not easily
constructed by a few lines of Python?
Albert
--
Unlike popular belief, the .doc format is not an open publically available format.
Jul 18 '05 #2
On 15 Jan 2004 23:06:44 -0800, jc*@iteris.com (MetalOne) wrote:
I am fairly new to Python.
Today, I wanted a priority queue.
I notice that Python does not have any sorted lists.


The standard library has modules Queue and bisect - go look them up in
the docs (online:
http://www.python.org/doc/current/lib/module-Queue.html and
http://www.python.org/doc/current/li...le-bisect.html ). These
should be what you're looking for.
--
Christopher
Jul 18 '05 #3
In article <92**************************@posting.google.com >,
MetalOne <jc*@iteris.com> wrote:

Today, I wanted a priority queue.
I notice that Python does not have any sorted lists.
I know that I can call list.sort(), but that seems rather inefficient
to call every time an element is added.
I am wondering why there is not a module or modules containing many
common data structures. Has such a thing been decided against? Is it
that just nobody has done it? Has nobody else suggested the need for
it? Maybe I should search, but I am too tired now, I need sleep.


There's a current discussion on python-dev about a "collections" module
or package, and that's one of the structures under discussion.
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

A: No.
Q: Is top-posting okay?
Jul 18 '05 #4
On Friday 16 January 2004 7:06 am, MetalOne wrote:
Today, I wanted a priority queue.
I notice that Python does not have any sorted lists.
I know that I can call list.sort(), but that seems rather inefficient
to call every time an element is added.
You've already had several good suggestions. I'll just add:

http://aspn.activestate.com/ASPN/Coo...n/Recipe/87369

In the paper version of the Python Cookbook Tim says he has a special fondness
for it, so it must be good!
I am wondering why there is not a module or modules containing many
common data structures. Has such a thing been decided against? Is it
that just nobody has done it? Has nobody else suggested the need for
it?


The python-dev list has been discussing the introduction of a data structures
package. Looking at the thread called "collections module" might give you an
insight to the thought processes involved.

James
--
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
Jul 18 '05 #5
On Fri, Jan 16, 2004 at 01:08:51PM -0500, Aahz wrote:
In article <92**************************@posting.google.com >,
MetalOne <jc*@iteris.com> wrote:

Today, I wanted a priority queue.
I notice that Python does not have any sorted lists.
I know that I can call list.sort(), but that seems rather inefficient
to call every time an element is added.
I am wondering why there is not a module or modules containing many
common data structures. Has such a thing been decided against? Is it
that just nobody has done it? Has nobody else suggested the need for
it? Maybe I should search, but I am too tired now, I need sleep.


There's a current discussion on python-dev about a "collections" module
or package, and that's one of the structures under discussion.


The major thread of the discussion there is about enhancing the built in
list type to handle popping the first item more efficiently behavior) so
the append/pop() idiom of implementing a queue will work in amortized O(1)
time.

I like the general direction this is going - no new basic data types.
Lists and dicts are sufficient for 98% of all will we ever need. The
remaining 2% can mostly be implemented in Python because it's rarely
performance-critical. The remaining cases are probably better handled by
specialized extension modules anyway (e.g. jkbuckets)

Oren
Jul 18 '05 #6

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

Similar topics

0
by: CatManDo | last post by:
Disclaimer #1: I am a Python newbie, and I appreciate the vast documentation at python.org -- some of which I expect has the answer to my question if I can find it. I am working on a custom...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
4
by: Dave | last post by:
Hi. I am learning PyOpenGL and I am working with a largish fixed scene composed of several thousand GLtriangles. I plan to store the coords and normals in a NumPy array. Is this the fastest...
1
by: Dennis Woos | last post by:
I am trying to get two structures to map the same data, like a union. Having failed to get the FieldOffset attribute to work at runtime, I tried: ...
2
by: volker_nitschke | last post by:
Hi, I want to develop a program, that transmits several classes between two processes. It should be built after the guidelines of the iso/osi-reference model and work with a shared memory. At...
9
by: tom arnall | last post by:
does anyone know of a utility to do a recursive dump of object data members? -- Posted via a free Usenet account from http://www.teranews.com
3
by: Warren DeLano | last post by:
I would like to parse arbitrary insecure text string containing nested Python data structures in eval-compatible form: # For example, given a "config.txt" such as: { 'my_atom' : 1.20,...
3
by: James Mills | last post by:
On Thu, Oct 9, 2008 at 2:26 PM, Warren DeLano <warren@delsci.comwrote: Yes it does :) I second this. It's far better to use Data Structures rather than Programming Constructs
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.