Invert a Dictionary Safely

easy
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 5. Everything before it counts as cleared.

Implement:

  • invert(d): swap keys and values. If two keys share a value, raise ValueError naming that value. That's a common silent bug when inverting naively.
  • invert_multi(d): map each value to a sorted list of all keys that had it.
  • invert_lists(d): the input maps keys to lists of values (like {"admin": ["alice", "bob"]}). Return a dict mapping each value to the sorted list of keys whose list contains it.
#dicts#data-structures2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Invert a Dictionary Safely · TechGradify