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:
* k*,

`v`_{i}

Each

value is called a`k`

_{i}*key*;each key is unique and immutable; and

the associated

*value*

can be of any type.`v`

_{i}

Another term for this structure is *mapping*, since it maps the set of keys
onto the set of values (in the algebraic sense).

To create a new dictionary, use this general form:

{:`k`

_{0},`v`

_{0}:`k`

_{1}, ... }`v`

_{1}

There can be any number of key-value pairs (including zero).
Each key-value has the form “

”, and
pairs are separated by commas. Here are some examples of
dictionaries:
* k*:

`v`_{i}

{} {'Bolton': 'Notlob', 'Ipswich': 'Esher'} {(1,1):48, (8,20): 52}

For efficiency reasons, the order of the pairs in a dictionary is arbitrary: it is essentially an unordered set of ordered pairs. If you display a dictionary, the pairs may be shown in a different order than you used when you created it.

>>> signals = {0:'red', 1: 'yellow', 2:'green'} >>> signals {2: 'green', 0: 'red', 1: 'yellow'}