A map or dictionary is a data structure similar to a list, except that a list's elements are indexed by integers from zero to the length of the list minus one, whereas a dictionary's values are indexed by keys, and a key can be anything at all as long as it is immutable. For example, a calendar might be represented as a dictionary where keys are time slots and values are events; then the calendar could hold one event for each time slot and look up the matching event given a time slot. We would say that the calendar "maps time slots to events".
In Python dictionaries (dict
s) are written as comma-separated key/value pairs in curly braces where
colons separate keys from values. For example, {'one': 1, 'two': 2}
is a dictionary with two strings
as its keys and two integers as its values. If a key is repeated, only its last occurrence is honored. For
instance, {(0, 1): True, (0, 1): False}
means the same thing as {(0, 1): False}
.
Note that the preferred way to write an empty dictionary is {}
, not dict()
.
Python's dictionaries are mutable; Python does not have an built-in immutable equivalent.
Fill in the placeholders so that the actual outputs match the expected outputs.