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 gyahun_dash
from itertools import chain
def check_connection(shakehands, me, you):
hands = {tuple(pair.split('-')) for pair in shakehands}
amigos = {me}
while amigos != set():
pairs = {pair for pair in hands if any(one in pair for one in amigos)}
amigos = set(chain(*pairs)) - amigos
if you in amigos: return True
hands -= pairs
return False
June 4, 2014
Comments: