taniyahreggienae
20.12.2019 •
Computers and Technology
The function below takes two arguments, a dictionary called dog_dictionary and a list of dog names (strings) adopted_dog_names. the dog dictionary uses dogs' names as the keys for the dictionary. complete the function to remove all the adopted dogs from the dog_dictionary. return the dictionary at the end of the function.
Solved
Show answers
More tips
- H Health and Medicine Liver Cleansing - Rejuvenation for the Body?...
- L Leisure and Entertainment Scrapbooking: What is it and Why is it Becoming More Popular?...
- H Horoscopes, Magic, Divination How to Cast a Love Spell on a Guy? Guide for Guys...
- F Family and Home How to Sew Curtain Tapes: Best Tips from Professionals...
- S Style and Beauty How are artificial nails removed?...
- S Style and Beauty How to Make Your Lips Fuller? Ideas and Tips for Beautiful Lips...
- F Food and Cooking The Disease That Haunted Abraham Lincoln...
- C Computers and Internet How to Get Rid of Windows Genuine Check?...
- H Health and Medicine How to perform artificial respiration?...
- S Style and Beauty Tricks and Tips: How to Get Rid of Freckles...
Answers on questions: Computers and Technology
- M Mathematics A variable X is normally distributed with mean 19 and standard deviation 9. Round your answers to the nearest hundredth as needed. a.) Determine the z-score for X = 19. b.)...
- E English Words that sound alike, but have a different meaning...
- H History How is andre carnegie spend his money...
- L Law A growing number of large police departments have begun requiring applicants for their academies to have previously received at a minimum an associate’s degree and preferably...
Ответ:
The solution code is written in Python.
def removeAdoptedDog(dog_dictionary, adopted_dog_names): for x in adopted_dog_names: del dog_dictionary[x] return dog_dictionary dog_dictionary = { "Charlie": "Male", "Max" : "Male", "Bella" : "Female", "Ruby": "Female", "Toby": "Male", "Coco": "Female", "Teddy": "Male" } print(dog_dictionary) adopted_dog_names = {"Ruby", "Teddy"} print(removeAdoptedDog(dog_dictionary, adopted_dog_names))Explanation:
Firstly, let's create a function removeAdoptedDog() takes two arguments, dog_dictionary & adopted_dog_names (Line 1)
Within the function, we can use a for-loop to traverse through the adopted_dog_names list and use the individual dog name as the key to remove the adopted dog from dog_dictionary (Line 3). To remove a key from a dictionary, we can use the keyword del.
Next return the updated dog_dictionary (Line 5).
Let's test our function by simply putting some sample records on the dog_dictionary (Line 7 -15) and two dog names to the adopted_dog_names list (Line 19).
Call the function removeAdoptedDog() by passing the dog_dictionary and adopted_dog_names as arguments. The display result will show the key represented by the adopted_dog_names have been removed from the dog_dictionary (Line 21).
Ответ: