Package Bio :: Package EUtils :: Module MultiDict :: Class OrderedMultiDict
[show private | hide private]
[frames | no frames]

Class OrderedMultiDict

_BaseMultiDict --+
                 |
                OrderedMultiDict


Store key/value mappings.

Acts like a standard dictionary with the following features:
>>> od = OrderedMultiDict([("Food", "Spam"), ("Color", "Blue"),
...                        ("Food", "Eggs"), ("Color", "Green")])
>>> od["Food"]
'Eggs'

>>> od.getall("Food")
['Spam', 'Eggs']

>>> list(od.allkeys())
['Food', 'Color', 'Food', 'Color']

>>>

The order of keys and values(eg, od.allkeys() and od.allitems()) preserves input order.

Can also pass in an object to the constructor which has an allitems() method that returns a list of key/value pairs.
Method Summary
  __init__(self, multidict)
  __delitem__(self, key)
Remove all values for the given key
  __eq__(self, other)
Does this OrderedMultiDict have the same contents and order as another?
  __ne__(self, other)
Does this OrderedMultiDict have different contents or order as another?
  __repr__(self)
  __setitem__(self, key, value)
Add a new key/value pair
  allitems(self)
iterate over all key/value pairs in input order
  allkeys(self)
iterate over all keys in input order
  allvalues(self)
iterate over all values in input order
    Inherited from _BaseMultiDict
  __contains__(self, key)
check if the key exists
  __getitem__(self, key)
value for a given key
  __iter__(self)
iterate through the list of unique keys
  __len__(self)
the number of unique keys
  __str__(self)
shows contents as if this is a dictionary
  get(self, key, default)
value for the given key; default = None if not present
  getall(self, key)
Get all values for a given key
  items(self)
unordered list of key/value pairs
  keys(self)
unordered list of unique keys
  values(self)
unordered list of values

Method Details

__delitem__(self, key)
(Index deletion operator)

Remove all values for the given key

__eq__(self, other)
(Equality operator)

Does this OrderedMultiDict have the same contents and order as another?

__ne__(self, other)

Does this OrderedMultiDict have different contents or order as another?

__setitem__(self, key, value)
(Index assignment operator)

Add a new key/value pair

If the key already exists, replaces the existing value so that d[key] is the new value and not the old one.

To get all values for a given key, use d.getall(key).

allitems(self)

iterate over all key/value pairs in input order

allkeys(self)

iterate over all keys in input order

allvalues(self)

iterate over all values in input order

Generated by Epydoc 2.1 on Thu Aug 10 20:05:43 2006 http://epydoc.sf.net