Dictionaries offer one often-used mutation method, setdefault
.
The setdefault
method behaves exactly like the get
method except that the returned
value is associated with the given key if that key is not in the dictionary. For instance,
{'one': 1, 'two': 2}.setdefault('two')
behaves just like {'one': 1, 'two': 2}.get('two')
,
returning 2
. But {'one': 1, 'two': 2}.setdefault('three')
not only returns
None
, it also updates the dictionary to be {'one': 1, 'two': 2, 'three': None}
. Likewise,
{'one': 1, 'two': 2}.setdefault('three', 100)
changes the dictionary to
{'one': 1, 'two': 2, 'three': 100}
before returning 100
.
Fill in the placeholders so that the actual outputs match the expected outputs.