-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
The Python Workshop
By :
A Python dictionary is an unordered collection. Dictionaries are written with curly brackets, and they have keys and values.
For instance, have a look at the following example, where you store the details of an employee:
employee = {
'name': "Jack Nelson",
'age': 32,
'department': "sales"
}
You might have noticed a certain resemblance between Python dictionaries and JSON. Although you can load JSON directly into Python, a Python dictionary is a complete data structure that implements its own algorithms, and JSON is just a pure string written in a similar format..
Python dictionaries are something similar to key-value pairs. They simply map keys to associated values, as shown in Figure 2.12:
Figure 2.12: Mapping keys and values in Python dictionaries
Dictionaries are like lists. They both share the following properties:
Change the font size
Change margin width
Change background colour