The in
and not in
operators can check whether a key is in a dictionary. For example,
'one' in {'one': 1, 'two': 2}
is true, but 'three' in {'one': 1, 'two': 2}
is false.
The dictionary's values are not considered, so 2 in {'one': 1, 'two': 2}
is also false.
The values
method can be used to get just a dictionary's values, which is useful for testing
whether the dictionary holds a particular value. For instance, {'one': 1, 'two': 2}.values()
is a
collection containing 1
and 2
, so 'two' in {'one': 1, 'two': 2}.values()
is false, and 2 in {'one': 1, 'two': 2}.values()
is true.
There is a keys
method, and it is possible to write an expression like
'two' in {'one': 1, 'two': 2}.keys()
, which means the same thing as
'two' in {'one': 1, 'two': 2}
, but this is considered bad style. The keys
method is
generally only used when the code needs to apply set operations on a dictionary's keys.
Fill in the placeholders so that the actual outputs match the expected outputs.