Dictionaries

--Originally published at Elu's Blog

A dictionary in Python3 is a type of data that contains a lot of information (that doesn’t have an order) and unique tags (called keys) for every piece of information.

Here is an example of defining a dictionary: dic = {‘house1′:’red’, ‘house2′:’blue’, ‘house3′:’green’}

As we can see, the dictionary variable is ‘dic’ and it has three elements, the first one has the key ‘house1’ and what’s in it is the word ‘red’, the second element has the key ‘house2’ and contains the word ‘blue’, finally the key ‘house3’ contains the string ‘green’. Remember that the elements are not in order.

If I wanted to know the color of the house1, I just write dic[house1] and it will return ‘red’.

So dictionaries let you store information that let you access it according to the keys.

Here is an alternative explanation:

Python 3 Programming Tutorial – Dictionaries by sentdex