python - I need to append a dictionary to a dictionary of dictionaries -


ok, have dictionary called food. food has 2 elements, both of dictionaries themselves, veg , dairy. veg has 2 elements root : turnip, , stem : asparagus. dairy has cheese : cheddar , yogurt : strawberry. have new dictionary fruit has red : cherry , yellow : banana.

food['veg']['root'] == 'turnip' food['dairy']['cheese'] == 'cheddar'  

etc and

fruit['red'] == 'cherry' 

now add "fruit" dictionary "food" dictionary in entirety, have:

food['fruit']['red'] == 'cherry' 

i know this:

food['fruit'] = fruit 

but seems clumsy. like

food.append(fruit) 

but doesn't need.

(edited removed initial capitals variable names, since seemed causing distraction.)

food['fruit'] = fruit right , proper way (apart capitalized names).

as @kindall wisely notes in comment, there can several names referencing same dictionary, why 1 can't build function maps object name , uses new key in food dict.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -