indexed dictionaries?

Kevin Jacobs jacobs at
Mon Apr 10 21:28:30 CEST 2000

David Goodger <dgoodger at> wrote:
> on 2000-04-09 22:30, Michal Wallace (sabren) (sabren at
> wrote:
>>  I'm looking for a cross between a dictionary and a list,
>> such that keys() always returns keys in the order in which they were
>> added, and that instance[0] refers to the first key...
> ...
>> Anyone got something like this?

> I have implemented a list/dictionary hybrid in my SGF Parser Library (class
> Node in ). It doesn't do ordered
> keys(), but it does do indexing by integer (note that in this library, no
> numeric dictionary keys will ever be used). It may give you a few ideas.

> Please send me a copy of your final implementation of indexed dictionaries;
> I'd be interested to see what you come up with.

Here is my rough 3 minute attempt.  


# WARNING: Untested code
class SequenceDict(UserDict):
  def __init__(self):
    self._seq = []

  def __setitem__(self,key,value):
    if not

  def __delitem__(self,key):

  def seq_keys(self):
    return self._seq

  def seq_items(self):
    return map(None, self._seq, self.seq_values())

  def seq_values(self):
    return map(operator.getitem, [self]*len(self._seq), self._seq)

----------->  Kevin Jacobs  <-----------|------->  (216) 778-8487  <--------
S.A.G.E. Project Technical Coordinator  | Department of Epidemiology
  & System Administrator                |   & Biostatistics
Internet E-mail: jacobs at | Case Western Reserve University

More information about the Python-list mailing list