Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Help coding Python 3 functions: The image below has the functions that need to be completed. Thank you! The image below has the functions that

Help coding Python 3 functions: The image below has the functions that need to be completed. Thank you!

image text in transcribed

The image below has the functions that need to be completed. def get_by_diett (animal_d, diet): Consider a dictionary, animal_d, where the keys are names of animals, and the values are descriptions of their diets. The function should search in the dictionary for animals that are labeled as diet, put them into a list and return the sorted list. Animal_d: a dictionary that maps animal names to their diet description. diet: the diet to search for. Return value: asciibetically sorted list of animals that are labeled as diet. Examples: get_by_diet ({'deer':' 'herbivore' 'bear': 'omnivore'}, 'herbivore') rightarrow ['deer'] get_by_diet ({'lion': 'carnivore', 'penguin': 'piscivore'}, 'omnivore') rightarrow [] 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: For a key s that belongs to only one of the original dictionaries in a pair likes s: xs, include the same pair in the new dictionary; For a key s that is present in both d1 and d2, like s: xs in d1 and s: ys in d2, includes: zs in the new dictionary where zs is the concatenation of xs and ys. Keep the duplicates in zs. Return value: the newly created dictionary. Do NOT update d1 or d2. Examples: d1 = {'cardinal': ['Virginia', 'Ohio'], 'meadowlark': ['Oregan']} d2 = {'robin': ['Connecticut']} d3 = {'meadowlark': ['Wyoming'] 'cardinal': ['Virginia', 'Illinois'], 'oriole': ['Maryland']} merge (d1, d2) rightarrow {' cardinal ':['Virginia', 'Ohio'], meadowlark': ['Oregan'], 'robin' ['Connecticut']} merge (d1, d3) rightarrow {' 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_2

Step: 3

blur-text-image_3

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

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students explore these related Databases questions