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, placing the original value as the new key, and the original key as the new value in the
mapping.items()dictionary.inverse - Print.
inverse
main.py
main.py
Ctrl + Enter