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 Vottivott
def check_connection(network, first, second):
groups = set()
for pair in network:
p = set(pair.split("-"))
new = p #The group to be added to groups
for g in groups.copy():
if g & p: #If any of the two new friends have friends in an existing group
new |= g
groups.remove(g)
groups.add(frozenset(new))
return any(first in g and second in g for g in groups)
Jan. 21, 2015