Dictionary Keys and Values
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:
Dictionaries are like lists. They both share the following properties:
- Both can...