Inverting a dictionary
๐ Scenario: Imagine you have a dictionary that stores the names of fruits as keys and their colors as values. You want to create a new dictionary that flips this information, so the colors become the keys and the fruits become the values.
๐ฏ Goal: Build a Python program that inverts a dictionary by swapping its keys and values.
๐ What You'll Learn
Create a dictionary with fruit names as keys and their colors as values
Create a variable to hold the inverted dictionary
Use a dictionary comprehension to invert the original dictionary
Print the inverted dictionary
๐ก Why This Matters
๐ Real World
Inverting dictionaries is useful when you want to look up information in reverse, like finding all fruits by their color instead of the other way around.
๐ผ Career
Understanding how to manipulate dictionaries and use comprehensions is important for data processing, software development, and many programming tasks.
Progress0 / 4 steps