I would like to give some feedback about ...
The code gets stuck in loading, it should pass.
From: http://www.checkio.org/mission/find-friends/solve/
HTTP\_USER\_AGENT:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
My Code:
def check_connection(network, first, second):
future = []
visited = []
dic = {}
for i in network:
a = i.split('-')
if a[0] in dic and dic[a[0]] != a[1]:
dic[a[0]].append(a[1])
else:
dic[a[0]] = [a[1]]
if a[1] in dic and dic[a[1]] != a[0]:
dic[a[1]].append(a[0])
else:
dic[a[1]] = [a[0]]
if [a[0]] in dic.values():
for key,val in dic.items():
if a[1] == key:
break
elif (''.join(ch for ch in val if ch.isalnum())) == str(a[0]):
dic[str(a[0])].append(key)
break
if first in dic:
for i in dic[first]:
if i == second:
return True
else:
future.append(i)
while len(future) != 0:
for i in future:
for g in dic[i]:
if g == second:
return True
else:
future.append(g)
future.remove(i)
else:
return False
Created at: 2014/08/03 22:36; Updated at: 2014/08/03 23:36