d={1:[2, 3], 2:[3], 3:[5], 4:[1], 5:[]} led=[1, 3] #d[1].remove(3) print(led[1]) d[led[0]].remove(d[led[1]]) ##viga print(d) hallid=[led[0]] mustad=[] while hallid: for tipp in d[hallid[0]]: if tipp not in hallid+mustad: hallid.append(tipp) mustad.append(hallid.pop(0)) print( "paralleel" if led[1] in mustad else "ainuke" ) d[led[0]].append(d[1]) print(hallid) print(mustad)