Question: In python3 No imports are allowed (: 2. friendsOfFriends(d) (10 pts] Background: we can create a dictionary mapping people to sets of their friends. For
![In python3 No imports are allowed (: 2. friendsOfFriends(d) (10 pts]](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f63f478ac82_08766f63f4707035.jpg)
In python3 No imports are allowed (:
2. friendsOfFriends(d) (10 pts] Background: we can create a dictionary mapping people to sets of their friends. For example, we might say: d = { } d["jon"] = set ( ["arya", "tyrion"]) d["tyrion"] = set(["jon", "jaime", "pod"]) d["arya"] = set(["jon"]) d["jaime"] = set(["tyrion", "brienne"]) d["brienne"] = set(["jaime", "pod"]) d["pod"] = set(["tyrion", "brienne", "jaime"]) d["ramsay"] = set() Copy With this in mind, write the function friendsOfFriends(d) that takes such a dictionary mapping people to sets of friends and returns a new dictionary mapping all the same people to sets of their friends of friends. For example, since Tyrion is a friend of Pod, and Jon is a friend of Tyrion, Jon is a friend- of-friend of Pod. This set should exclude any direct friends, so Jaime does not count as a friend-of-friend of Pod (since he is simply a friend of Pod) despite also being a friend of Tyrion's. Thus, in this example, friendsOfFriends should return: { 'tyrion': {'arya', 'brienne'}, 'pod': {'jon'}, 'brienne': {'tyrion'}, 'arya': {'tyrion'}, 'jon': {'pod', 'jaime'}, jaime': {'pod', 'jon'}, 'ramsay': set) } Copy C Copy
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
