Ordered Dictionary Recipe¶
-
class
sortedcollections.
OrderedDict
(*args, **kwargs)¶ 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>)¶ del ordered_dict[key]
-
__eq__
(other)¶ Test self and other mapping for equality.
-
__iter__
()¶ iter(ordered_dict)
-
__ne__
¶ Return self!=value.
-
__reduce__
()¶ Support for pickling serialization.
-
__repr__
()¶ Text representation of mapping.
-
__reversed__
()¶ reversed(ordered_dict)
-
__setitem__
(key, value, dict_setitem=<slot wrapper '__setitem__' of 'dict' objects>)¶ 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>)¶ Remove all items from mapping.
-
copy
()¶ Return shallow copy of mapping.
-
classmethod
fromkeys
(iterable, value=None)¶ Return new mapping with keys from iterable.
If not specified, value defaults to None.
-
items
()¶ Return set-like and sequence-like view of mapping items.
-
keys
()¶ Return set-like and sequence-like view of mapping keys.
-
pop
(key, default=<object object>)¶ Remove given key and return corresponding value.
If key is not found, default is returned if given, otherwise raise KeyError.
-
popitem
(last=True)¶ 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)¶ Return
mapping.get(key, default)
, also setmapping[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
()¶ Return set-like and sequence-like view of mapping values.
-
-
class
sortedcollections.ordereddict.
KeysView
(mapping)¶ Read-only view of mapping keys.
-
__getitem__
(index)¶ keys_view[index]
-
__weakref__
¶ list of weak references to the object (if defined)
-