#class step: # def __init__(self, name, unlocks): # self.name = name; # self.unlocks = unlocks; def TransInstr (instruction): return [instruction[5], instruction[36]]; myinput = {}; currentfilename = "input.txt"; #currentfilename = "testinput.txt"; f = open(currentfilename, 'r'); #list1 = []; #list2 = {}; list2 = set(); for line in f: nowinstr = TransInstr(line); #myinput[nowinstr[1]].append(nowinstr[0]); list2.add(nowinstr[0]); #''' try: myinput[nowinstr[1]].append(nowinstr[0]); #myinput[nowinstr[1]] = nowinstr[0]; except: myinput[nowinstr[1]] = []; myinput[nowinstr[1]].append(nowinstr[0]); #''' print(myinput.keys()); print("##############"); print(list2); print("##############"); pr1 = list(myinput.keys()); pr1.sort(); pr2 = list(list2); pr2.sort(); print(pr1); print(pr2); print("##############"); print("##############"); print("finding the first step"); CurrentStep = ''; AvailableSteps = []; #AvailableSteps.append(CurrentStep); for l in list2: IsUnique = True; for k in myinput.keys(): #print("L ", l, "\tK ",k, "\t",l == k); if (l == k): IsUnique = False; break; if IsUnique: #CurrentStep = l; #break; AvailableSteps.append(l); print("Unique values are ", AvailableSteps); print("##############"); print(myinput); print("##############"); part1 = ""; #CurrentStep; #list1 = myinput.keys(); #list1.append(CurrentStep); #print(list1); while (len(AvailableSteps) != 0): #input(); AvailableSteps.sort(); CurrentStep = AvailableSteps[0]; part1 += CurrentStep; print("now ", CurrentStep); for step in myinput: #x = myinput[step].index(CurrentStep); #print(x, "\t",myinput[step]); #myinput[step].pop(0); #print(x, "\t",myinput[step]); try: #print("try worked"); myinput[step].pop(myinput[step].index(CurrentStep)); except: #print("skip"); pass; if (len(myinput[step]) == 0 and part1.find(step) == -1): AvailableSteps.append(step); AvailableSteps.pop(0); print("##################################"); def RemoveDupsOrder(TheString): a = ""; for letter in TheString: if not (letter in a): a += letter; return a; print(part1); part1 = RemoveDupsOrder(part1); print(part1);