Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simplest v2 solution in Clear category for How to Find Friends by andriiabaimov
def check_connection(net, first, second):
visited, future = set(), set()
future.add(first)
while future and second not in future:
r = future.pop()
visited.add(r)
amigos = ([x for x in n.split('-') if x != r][0] for n in net if r in n)
future |= set(amigo for amigo in amigos if amigo not in visited)
return True if second in future else False
Dec. 22, 2015