Back to Lesson

Value Swapper

Invert a dictionary using iteration.

Instructions

  • Given
    mapping = {"a": 1, "b": 2, "c": 3}
    .
  • Create a new, empty dictionary
    inverse = {}
    .
  • Iterate over
    mapping.items()
    , placing the original value as the new key, and the original key as the new value in the
    inverse
    dictionary.
  • Print
    inverse
    .
main.py
main.py