Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def path_to_friend(network, user_A, user_B, if path is None: path = []):
  2. if user_A not in network['connection'] or user_B not in network['connection']:
  3. return None
  4. if user_A == user_B:
  5. return path.append(user_A)
  6. else:
  7. path = path + [user_A]
  8. for connection in network['connection'][user_A]:
  9. if connection not in path:
  10. path_to_friend(network, connection, user_B, path)
  11. if path[-1] == user_B:
  12. return path
  13. path.pop()
  14. return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement