Say I have two dictionaries:
animal = {
"CA": "Grizzly Bear",
"ID": "Appaloosa",
"NY": 'Beaver'
}
flower = {
"CA": "tulip",
"ID": "syringa",
"NY": 'rose'
}
How can I combine these two dictionaries into a nested dictionary with the level of state > animal/flower > value. Like the following:
dict3 = {'CA': {'animal':'Grizzly Bear','flower':'tulip'},
'ID': {'animal':'Appaloosa','flower':'syringa'},
'NY': {'animal':'Beaver','flower':'rose'}}
print(dict3)
The code above works manually but I want to know a more efficient way to to this with any amount of states. I imagine I would rearrange the key/values with loops but I am wondering if there is an efficient way.
Thanks!