Ordered Dictionary Recipe¶
-
class
sortedcollections.OrderedDict(*args, **kwargs)¶ Dictionary that remembers insertion order and is numerically indexable.
Keys are numerically indexable using the
ilocattribute. For example:>>> ordered_dict = OrderedDict.fromkeys('abcde') >>> ordered_dict.iloc[0] 'a' >>> ordered_dict.iloc[-2:] ['d', 'e']
The
ilocattribute behaves as a sequence-view for the mapping.-
__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()¶ List of (key, value) item pairs in mapping.
-
iteritems()¶ Return iterator over the (key, value) item pairs in mapping.
-
iterkeys()¶ Return iterator over the keys in mapping.
-
itervalues()¶ Return iterator over the values in mapping.
-
keys()¶ List of keys in mapping.
-
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] = defaultif 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()¶ List of values in mapping.
-
viewitems()¶ Return set-like object with view of mapping items.
-
viewkeys()¶ Return set-like object with view of mapping keys.
-
viewvalues()¶ Return object with view of mapping values.
-
-
class
sortedcollections.ordereddict.KeysView(mapping)¶ Read-only view of mapping keys.
-
__reversed__()¶ reversed(keys_view)
-
__weakref__¶ list of weak references to the object (if defined)
-