Ok, I have a dictionary called food. food has two elements, both of which are dictionaries themselves, veg and dairy. veg has two elements root : Turnip, and stem : Asparagus. dairy has cheese : Cheddar and yogurt : Strawberry. I also have a new dictionary fruit which has red : Cherry and yellow : Banana.
food['veg']['root'] == 'Turnip'
food['dairy']['cheese'] == 'Cheddar'
etc and
fruit['red'] == 'Cherry'
Now I would like to add the “fruit” dictionary to the “food” dictionary in its entirety, so that I will have:
food['fruit']['red'] == 'Cherry'
I know that I could do something like this:
food['fruit'] = fruit
But that seems clumsy. I would like to do something like
food.Append(fruit)
But that doesn’t do what I need.
(Edited to removed the initial capitals from variable names, since that seemed to be causing a distraction.)
Food['Fruit'] = Fruitis the right and proper way (apart from the capitalized names).As @kindall wisely notes in the comment, there can be several names referencing the same dictionary, which is why one can’t build a function that maps the object to its name and uses that as the new key in your
fooddict.