Basic dictionary comprehension
๐ Scenario: You work in a small bookstore. You have a list of books with their prices. You want to create a new dictionary that shows the prices after a discount.
๐ฏ Goal: Create a dictionary using dictionary comprehension to apply a discount to each book price.
๐ What You'll Learn
Create a dictionary called
books with given book titles and prices.Create a variable called
discount to hold the discount rate.Use dictionary comprehension to create a new dictionary called
discounted_books with discounted prices.Print the
discounted_books dictionary.๐ก Why This Matters
๐ Real World
Applying discounts to product prices is common in stores and online shops.
๐ผ Career
Understanding dictionary comprehension helps in data processing and automation tasks in many programming jobs.
Progress0 / 4 steps