Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def path_finder(path_graph, user_A, user_B, friend_path=[]):
- friend_path = friend_path + [user_A]
- if user_A == user_B:
- return friend_path
- if user_A not in path_graph:
- return None
- for user in path_graph[user_A]:
- if user not in friend_path:
- final_path = path_finder(path_graph, user, user_B, friend_path)
- if final_path:
- return final_path
- return None
- def path_to_friend(network, user_A, user_B):
- path_graph = {}
- friend_path = []
- for user_key in network:
- path_graph[user_key] = network[user_key][0]
- path_to_friend = path_finder(path_graph, user_A, user_B, friend_path)
- return path_to_friend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement