I am thinking if I give up this task...
Would you give me some advice?
I got "MemoryError" with this code, although I know I use "for" too much.
import collections
def check_connection(network, first, second):
box=collections.defaultdict(list)
result={}
for l in network:
(x,y) = l.split('-')
box[x].append(y)
box[y].append(x)
for k1, v1 in box.iteritems():
for k2, v2 in box.iteritems():
if k1 != k2:
for x in v2:
if k1 in v2 or x in v1:
v1.extend(v2)
result[k1] = set(v1)
for key in result.keys():
if first in result[second]:
return True
else:
return False
Created at: 2015/11/13 08:53; Updated at: 2015/11/15 18:18