an indexed list - how to do it in python

Aahz Maruch aahz at netcom.com
Sat Aug 12 17:35:04 EDT 2000


In article <8n3tm2$jug$1 at nnrp1.deja.com>,  <dmost at magna.com.au> wrote:
>
>I want to create, in Python, an object that mixes the behavior of a
>sequence and a mapping. The primary behavior should be that of a
>mutable sequence, or list, but the objects in the list should also be
>accessible by a key value.

How many items?  What performance do you need?  One option would be to
write a wrapper class that maintains the info as *both* a dict and a
list.  Then the only tricky part is inserting new items by order into
the list (which will be O(N)).
--
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Gun-toting Naderite / socialized medicine libertarian



More information about the Python-list mailing list