It’s about Merging or Updating Dictionaries
In task 3. Update Recipe “Ideas” Section
When you code like below, you pass the test
=============================
def update_recipes(ideas, recipe_updates):
"""Update the recipe ideas dictionary.
:param ideas: dict - The "recipe ideas" dict.
:param recipe_updates: *dict* - dictionary with updates for the ideas section.
**->I think it should be changed, because a tuple or a list of key-value pairs, not a dict, is used in the example and the test data.**
:return: dict - updated "recipe ideas" dict.
"""
ideas.update(recipe_updates)
return ideas
==========================
but in the example, below
> update_recipes({'Banana Bread' : {'Banana': 1, 'Apple': 1, 'Walnuts': 1, 'Flour': 1, 'Eggs': 2, 'Butter': 1},
'Raspberry Pie' : {'Raspberry': 1, 'Orange': 1, 'Pie Crust': 1, 'Cream Custard': 1}},
(('Banana Bread', {'Banana': 4, 'Walnuts': 2, 'Flour': 1, 'Butter': 1, 'Milk': 2, 'Eggs': 3}),))
...
#the result is
>>{'Banana Bread' : {'Banana': 4, **'Apple': 1**, 'Walnuts': 2, 'Flour': 1, 'Butter': 1, 'Milk': 2, 'Eggs': 3},
'Raspberry Pie' : {'Raspberry': 1, 'Orange': 1, 'Pie Crust': 1, 'Cream Custard': 1}}
‘Apple’:1 is still in the result.
But in update method, when keys in the two dictionaries overlap , the value
in dict_one
should be overwritten by the corresponding value
from dict_two
, not appended.
I wonder if the answers or this example shoude be changed.