Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for How to Find Friends by lexin13
from functools import reduce
def check_connection(network, first, second):
net = [set(x.split('-')) for x in network]
for i in range(len(net)):
net = reduce(lambda x, y: [x[0] | y] + x[1:] if x[0] & y else x + [y], net, [{first}])
if second in net[0]:
return True
return False
March 19, 2016