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

Class OrderedMultiDict

source code

_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.

Instance Methods [hide private]
 
__init__(self, multidict=None) source code
 
__eq__(self, other)
Does this OrderedMultiDict have the same contents and order as another?
source code
 
__ne__(self, other)
Does this OrderedMultiDict have different contents or order as another?
source code
 
__repr__(self) source code
 
__setitem__(self, key, value)
Add a new key/value pair
source code
 
__delitem__(self, key)
Remove all values for the given key
source code
 
allkeys(self)
iterate over all keys in input order
source code
 
allvalues(self)
iterate over all values in input order
source code
 
allitems(self)
iterate over all key/value pairs in input order
source code

Inherited from _BaseMultiDict: __contains__, __getitem__, __iter__, __len__, __str__, get, getall, items, keys, values

Method Details [hide private]

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

source code 

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).