Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions