Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. def path_finder(path_graph, user_A, user_B, friend_path=[]):
  2. friend_path = friend_path + [user_A]
  3. if user_A == user_B:
  4. return friend_path
  5. if user_A not in path_graph:
  6. return None
  7. for user in path_graph[user_A]:
  8. if user not in friend_path:
  9. final_path = path_finder(path_graph, user, user_B, friend_path)
  10. if final_path:
  11. return final_path
  12. return None
  13.  
  14. def path_to_friend(network, user_A, user_B):
  15. path_graph = {}
  16. friend_path = []
  17. for user_key in network:
  18. path_graph[user_key] = network[user_key][0]
  19. path_to_friend = path_finder(path_graph, user_A, user_B, friend_path)
  20. return path_to_friend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement