Question
def merge(d1,d2): Consider two dictionaries d1 and d2 of the same structure: with strings as keys and a list as values. This function creates a
def merge(d1,d2): Consider two dictionaries d1 and d2 of the same structure: with strings as keys and a list as values. This function creates a combined dictionary of the same structure but with the merged information from both d1 and d2:
o For a key s that belongs to only one of the original dictionaries in a pair like s:xs, include the same pair in the new dictionary;
o For a key s that is present in both d1 and d2, like s:xs in d1 and s:ys in d2, include s:zs in the new dictionary where zs is the concatenation of xs and ys. Keep the duplicates in zs.
o Return value: the newly created dictionary. Do NOT update d1 or d2.
? Examples:
o d1 = {'cardinal':['Virginia','Ohio'],'meadowlark':['Oregan']}
o d2 = {'robin': ['Connecticut']}
o d3 = {'meadowlark':['Wyoming'],'cardinal':['Virginia','Illinois'], 'oriole':['Maryland']} o merge(d1,d2) ? {'cardinal':['Virginia','Ohio'],'meadowlark':['Oregan'],'robin': ['Connecticut']} o merge(d1,d3) ? {'cardinal':['Virginia','Ohio','Virginia','Illinois'],'meadowlark':['Oregan', 'Wyoming'], 'oriole':['Maryland']}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started