Reverse

The questions below are due on Sunday July 13, 2025; 10:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

Write a function dict_reverse that returns a new dictionary with all the key-value pairs in the input dictionary reversed. That is, if there is a key "foo" in the input dictionary with corresponding value 1, then there is a key 1 with corresponding value "foo" in the reversed dictionary.

For example:

  • dict_reverse({'foo': 1, 'bar': 2, 'baz': 3}) will return a new dictionary that looks like {1: 'foo', 2: 'bar', 3: 'baz'}

For the purposes of this exercise, you can assume that any input dictionary has unique values, and each value is hashable.

  No file selected

Next Exercise: Removing Duplicates

Back to exercises