Python dictionaries are one of its more powerful built-in types. They are generally used for look-up tables and many similar applications.
A Python dictionary represents a set of
zero or more ordered pairs (
such that:ki,
vi)
Each
value is called a key;ki
each key is unique and immutable; and
the associated value
can be of any type.vi
Another term for this structure is mapping, since it maps the set of keys onto the set of values.
These operations are available on any dictionary object
:D
len( | Returns the number of entries in
. |
| If |
| Sets the entry for key
to value . If there was
previously a value for that key, it is replaced. |
del | If there is an entry for key
,
that entry is deleted. If not, a
KeyError exception is
raised. |
| Predicate
that returns true if has a key
. |
| A list of (key,value) tuples
from . |
| A list of all keys in . |
| A list of all values in
,
in the same order as
. |
| Merge dictionary into
.
If the same key exists in both, use the value
from . |
| Same as , but if no entry exists for key
,
returns , or None if
is omitted. |
| If
exists, returns that value. If there is no element
,
sets
to , defaulting to
None, and returns that
value. |
| Returns an iterator over the
(,
)
pairs of . |
| Returns an iterator over the keys of
. |
| Returns an iterator over the values of
. |
| Returns an arbitrary entry from
as a (
tuple, and also removes that entry. If
is empty, raises a KeyError
exception. |
| True if is a key in
. |
| True if is not a key in
. |