On June 18th at 10:00 AM UTC Academy will be unavailable for 5 minutes due to planned maintenance break.
Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close
Dictionary basics
Dictionaries in loops and conditional statements
Dictionaries in functions
15. Functions with dictionaries – practice


Perfect, it's time for additional practice!


Write a function named calculate_discount() that takes two dictionaries: base_prices and discounts. Both dictionaries have strings as keys and integers as values. For each item in base_prices, if there is an item with the same key in discounts, subtract the discounts value from the base_prices value. Return a dictionary with the new, discounted prices. If there was no discount for a given item, return it as it was. For instance, for the following input data:

base_prices = {
  'shoes': 235,
  't-shirt': 49,
  'pullover': 109

discounts = {
  'shoes': 40,
  'pullover': 9

Your function should return the following dictionary:

discounted_prices = {
  'shoes': 195,
  't-shirt': 49,
  'pullover': 100

Stuck? Here's a hint!

Copy the original dictionary with: