We'll now return to dictionaries, which lie at the heart of many Python programs, including the Python interpreter itself. We briefly looked at literal dictionaries previously, seeing how they are delimited with curly braces and contain comma-separated key value pairs, with each pair tied together by a colon:
>>> urls = {'Google': 'http://google.com', ... 'Twitter': 'http://twitter.com', ... 'Sixty North': 'http://sixty-north.com', ... 'Microsoft': 'http://microsoft.com' } >>>
A dictionary of URLs. The order of dictionary keys is not preserved, refer to the following diagram:
Figure 5.20: Dictionary
The values are accessible via the keys:
>>> urls['Twitter'] http://twitter.com
Since each key is associated with exactly one value, and lookup is through keys, the keys must be unique within any single dictionary. It's fine, however, to have duplicate values.
Internally, the dictionary maintains pairs of references to the key objects and...