Ordered Dictionary Recipe

class sortedcollections.OrderedDict(*args, **kwargs)[source]

Dictionary that remembers insertion order and is numerically indexable.

Keys are numerically indexable using dict views. For example:

>>> ordered_dict = OrderedDict.fromkeys('abcde')
>>> keys = ordered_dict.keys()
>>> keys[0]
'a'
>>> keys[-2:]
['d', 'e']

The dict views support the sequence abstract base class.

__delitem__(key, dict_delitem=<slot wrapper '__delitem__' of 'dict' objects>)[source]

del ordered_dict[key]

__eq__(other)[source]

Test self and other mapping for equality.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

__iter__()[source]

iter(ordered_dict)

__ne__(value, /)

Return self!=value.

__reduce__()[source]

Support for pickling serialization.

__repr__()[source]

Text representation of mapping.

__reversed__()[source]

reversed(ordered_dict)

__setitem__(key, value, dict_setitem=<slot wrapper '__setitem__' of 'dict' objects>)[source]

ordered_dict[key] = value

__str__()

Text representation of mapping.

__weakref__

list of weak references to the object (if defined)

clear(dict_clear=<method 'clear' of 'dict' objects>)[source]

Remove all items from mapping.

copy()[source]

Return shallow copy of mapping.

classmethod fromkeys(iterable, value=None)[source]

Return new mapping with keys from iterable.

If not specified, value defaults to None.

items()[source]

Return set-like and sequence-like view of mapping items.

keys()[source]

Return set-like and sequence-like view of mapping keys.

pop(key, default=<object object>)[source]

Remove given key and return corresponding value.

If key is not found, default is returned if given, otherwise raise KeyError.

popitem(last=True)[source]

Remove and return (key, value) item pair.

Pairs are returned in LIFO order if last is True or FIFO order if False.

setdefault(key, default=None)[source]

Return mapping.get(key, default), also set mapping[key] = default if key not in mapping.

update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values()[source]

Return set-like and sequence-like view of mapping values.

class sortedcollections.ordereddict.KeysView(mapping)[source]

Read-only view of mapping keys.

__getitem__(index)[source]

keys_view[index]

__weakref__

list of weak references to the object (if defined)

class sortedcollections.ordereddict.ItemsView(mapping)[source]

Read-only view of mapping items.

__getitem__(index)[source]

items_view[index]

__weakref__

list of weak references to the object (if defined)

class sortedcollections.ordereddict.ValuesView(mapping)[source]

Read-only view of mapping values.

__getitem__(index)[source]

items_view[index]

__weakref__

list of weak references to the object (if defined)