Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def path_to_friend(network, user_A,user_B, path=None, variable=None):
- if user_A not in network or user_B not in network:
- return None
- if path == None:
- path=[user_A]
- if user_B in network[user_A][0] or user_B==user_A:
- path=path+[user_B]
- return path
- for i in network[user_A][0]:
- variable=path_to_friend(network,i,user_B,path)
- if i not in path and variable:
- path=path+[i]
- return variable
- return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement