fruit_prices is a dictionary that maps a fruit name to its price. fruits is a
list of four fruit names.
Write dictionary_operations(fruit_prices, fruits) that modifies fruit_prices
in place, in this order:
fruits[0] to fruit_prices with the price 3 (if it is already there, its price becomes 3).fruits[1] to 2.fruits[2] by 2.fruits[3] (and its value) from fruit_prices.The same name may appear more than once in fruits; just apply the steps in
order. The function returns nothing -- the dictionary itself is the result.
Example
fruit_prices = {'Apple': 2, 'Banana': 3, 'Grapes': 3, 'Orange': 4}
fruits = ['Mango', 'Apple', 'Grapes', 'Orange']
After the call, fruit_prices is {'Apple': 2, 'Banana': 3, 'Grapes': 5, 'Mango': 3}.
Implement this function:
def dictionary_operations(fruit_prices: dict, fruits: list):
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: fruit_prices, fruits.
Input
{'Apple': 2, 'Banana': 3, 'Grapes': 3, 'Orange': 4, 'Papaya': 5}
['Mango', 'Apple', 'Grapes', 'Orange']
Output
{'Apple': 2, 'Banana': 3, 'Grapes': 5, 'Papaya': 5, 'Mango': 3}