lab8-extra¶
reverse_dic(d)
¶
Implement a function reverse_dic(d)
that takes a dictionary d
as
the input argument and returns a dictionary r
. If the dictionary
d
has a key k
and an associated value v
, then the dictionary
r
should have a key v
and a value k
.
(This is only expected to work for dictionaries that have a unique set of values although you do not need to check for this.)
Example:
>>> d = {'key1': 'value1'}
>>> r = reverse_dic(d)
>>> r
{'value1': 'key1'}
>>> reverse_dic({'dog': 10, 'cat': 20})
{10: 'dog', 20: 'cat'}
Please include the extra tasks in your file lab8.py
and submit as Computing lab8 assignment.
Back to lab8.
End of lab8-extra.