People You May Know

Python for AIHard+10 XP+10

People You May Know

A social app suggests new friends. friendships is a list of tuples (name_a, name_b), each meaning those two people are friends. Friendship goes both ways.

A suggestion for person is someone who:

  • is a friend of one of person's friends,
  • is not already person's friend,
  • and is not person themself.

Task: write suggest_friends(person, friendships). Return the suggestions, each once, as a list sorted alphabetically. If there are none, return [].

Examples

person = "ana"
friendships = [("ana", "bo"), ("bo", "cy"), ("cy", "dee"), ("eli", "bo")]
returns ['cy', 'eli']
person = "zed"
friendships = [("ana", "bo")]
returns []

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run