Question
def get_by_diet(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
def get_by_diet(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.
o animal_d: a dictionary that maps animal names to their diet description.
o diet: the diet to search for.
o Return value: asciibetically sorted list of animals that are labeled as diet.
? Examples:
o get_by_diet({'deer':'herbivore', 'bear':'omnivore'}, 'herbivore') ? ['deer']
o get_by_diet({'lion':'carnivore', 'penguin':'piscivore'}, 'omnivore') ? [ ]
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