Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import functools
- def suggest_people_you_may_know(graph, user):
- friends = graph[user]
- suggestions = set()
- def reducer(acc, elem):
- friendsOfFriend = graph[elem]
- def reducer2(acc2, elem2):
- if elem2 != user and elem2 not in friends:
- suggestions.add(elem2)
- functools.reduce(reducer2, friendsOfFriend, None)
- functools.reduce(reducer, friends, None)
- return suggestions
- g = {
- "Ana": ["Andrei", "Bogdan", "Maria"],
- "Andrei": ["Ana", "Bogdan", "Robert"],
- "Bogdan": ["Ana", "Andrei"],
- "Maria": ["Ana"],
- "Robert": ["Andrei"]
- }
- print(suggest_people_you_may_know(g, "Bogdan"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement