class documentation

class MultiDict(defaultdict):

Constructor: MultiDict(dct)

View In Hierarchy

Implementation of a multi-dictionary. Keys can occur multiple times.

Internally, the MultiDict is a defaultdict with list for each key that can hold multiple values.

Method __init__ Initialize the MultiDict.
Method __repr__ Return a string representation of the MultiDict.
Method __setitem__ Set an item in the MultiDict.
Method __str__ Return a string representation of the MultiDict.
Method get Get a value for a key. This returns a list of all values for the key.
Method getOne Get one value for a key. If the key has multiple values, the first value is returned.
def __init__(self, dct: dict = None):

Initialize the MultiDict.

Parameters
dct:dictA dictionary to initialize the MultiDict with.
def __repr__(self) -> str:

Return a string representation of the MultiDict.

Returns
strA string representation of the MultiDict.
def __setitem__(self, key: Any, value: Any):

Set an item in the MultiDict.

Parameters
key:AnyThe key to set.
value:AnyThe value to set.
def __str__(self) -> str:

Return a string representation of the MultiDict.

Returns
strA string representation of the MultiDict.
def get(self, key: Any, default: Any = None, greedy: bool = False, flatten: bool = False) -> Any:

Get a value for a key. This returns a list of all values for the key.

Parameters
key:AnyThe key to get the value lisz for.
default:AnyThe default value to return if the key does not exist.
greedy:boolIf True, the value is removed from the MultiDict. This removes the key and all values.
flatten:boolIf True, and the value is a list with only one element, the element is returned instead of the list.
Returns
AnyThe value for the key.
def getOne(self, key: Any, default: Any = None, greedy: bool = False) -> Any:

Get one value for a key. If the key has multiple values, the first value is returned.

Parameters
key:AnyThe key to get the value for.
default:AnyThe default value to return if the key does not exist.
greedy:boolIf True, the value is removed from the MultiDict. This is only the value, not the key. The key is only removed if all values are removed.
Returns
AnyThe value for the key.