Sorted associative container in Python?

Max Khesin max at cNOvSisiPonAtecMh.com
Thu May 22 10:47:44 EDT 2003


This 'feature' is probably due to the fact that Python allows mixed key
types, where the sort order is not stricly defined. Wouldn't be a bad idea
to have a separate datastructure confirming to the std::map properties (even
with single-key type restriction) - it is easy enough in the datastructure
sense; maybe someone already wrote an extension for this?

--
========================================
Max Khesin, software developer -
max at cNvOiSsPiAoMntech.com
[check out our image compression software at www.cvisiontech.com, JBIG2-PDF
compression @
www.cvisiontech.com/cvistapdf.html]


"Roy Smith" <roy at panix.com> wrote in message
news:roy-A36B0E.08371022052003 at reader1.panix.com...
> C++ STL's map is a sorted associative container, with the following
> properties:
>
> 1) You can iterate over the entries in key-sorted order in linear time.
> 2) You can access any given key in log time.
> 3) Keys can be arbitrary type values.
>
> What's the best way to do that in Python?  A dictionary gives you #2 (or
> maybe even constant time?) and #3, but fails #1.  A list fails #3.






More information about the Python-list mailing list