Python summary: dictionaries

If we open a paper dictionary, we see a set of terms and its definitions, which are pairs (term+definition). In Python, dictionary has the same, but under other terminology:

term                    key
  definition              value


The structure of the dictionaries is:

{key: value}

The ampersands ({ and }) delimits the dictionary. Within, the key and value are divided by a colon (:).

And if our dictionary contains more keys and values, they are divided by comma (,):

{key: value, key: value}


The items can contain different built-in data types:

{'name': 'Enric Baltasar', 'age': 20}

However, about mutable and immutable types, combinations such as tuple-list (in form key-value) do not possible:

Key Value
Immutable Mutable/Immutable


Moreover, Python dictionaries are not paper dictionaries: in Python, the pairs have not order (but sort ways exist).

>>> {'name": 'Enric Baltasar', 'age': 20}
{'age': 20, 'name': 'Enric Baltasar'}


At last, we let’s save the dictionary on the variable our_dictionary for working with it (1), check its contain (2) and view is it a dict type (3):

>>> our_dictionary = {'name': 'Enric Baltasar', 'age': 20}
>>> our_dictionary
{'age': 20, 'name': 'Enric Baltasar'}
>>> type(dictionary)
<class 'dict'>



Be First to Comment

Deja un comentario