Answer:
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 <em>removeAdoptedDog() </em>takes two arguments, <em>dog_dictionary </em>& <em>adopted_dog_names</em> (Line 1)
Within the function, we can use a for-loop to traverse through the <em>adopted_dog_names</em> list and use the individual dog name as the key to remove the adopted dog from <em>dog_dictionary </em>(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 <em>dog_dictionary</em> (Line 7 -15) and two dog names to the <em>adopted_dog_names list</em> (Line 19).
Call the function <em>removeAdoptedDog() </em>by<em> </em>passing the <em>dog_dictionary and adopted_dog_names </em>as arguments. The display result will show the key represented by the<em> adopted_dog_names</em> have been removed from the <em>dog_dictionary </em>(Line 21).