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]
-
__ne__
(value, /)¶ Return self!=value.
-
__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)
-
classmethod
fromkeys
(iterable, value=None)[source]¶ Return new mapping with keys from iterable.
If not specified, value defaults to None.
-
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 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
-
-
class
sortedcollections.ordereddict.
KeysView
(mapping)[source]¶ Read-only view of mapping keys.
-
__weakref__
¶ list of weak references to the object (if defined)
-