data structures module

Albert Hofkamp hat at se-126.se.wtb.tue.nl
Fri Jan 16 03:37:42 EST 2004


On 15 Jan 2004 23:06:44 -0800, MetalOne <jcb at 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.



More information about the Python-list mailing list