Dictionaries

General Information
Dictionaries is a data type in Python.

This type is closely related to Lists, but it has the key advantage of so-called Keys. That also explains the name, we have a key and the description to it. Furthermore, this can contain several types, but the key has to be a String.

To explain this, we look at the Syntax:

The Syntax
Lets look at a basic example of a Dictionary:

Please note the structure: The main advantage here is that we don't have to write something abstract like  as in lists.

Operations on dictionaries
Python let us operate in different ways on dictionaries:

Adding elements
To add a new element, we just call it:

Changing values
To change values/descriptions of already existing entries, we call it again:

Deleting entries
To delete entries from this structure, we use the widely used del command:

keys
This function list up all keys:

get(KEY)
This function returns the value of the key KEY in the dictionary:

has_key(KEY)
This function returns True, if the key KEY is an element of the dictionary, False if not:

items
This function zips up all elements of a dictionary to a list of tupels, where the left side of the tuple is the key and the right one the value:

pop(KEY)
This well-known function returns the entry with the key KEY from the dictionary and returns this element:

values
This function is the exact opposite of the keys function, so it returns a list of all values: