Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def path_to_friend(network, user_A, user_B, if path is None: path = []):
- if user_A not in network['connection'] or user_B not in network['connection']:
- return None
- if user_A == user_B:
- return path.append(user_A)
- else:
- path = path + [user_A]
- for connection in network['connection'][user_A]:
- if connection not in path:
- path_to_friend(network, connection, user_B, path)
- if path[-1] == user_B:
- return path
- path.pop()
- return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement