def Filewrite(E): fo = open("example1.model", "w") #f = open("patterns.txt","w") for i in E: print(type(i)) #f.write(i) print(i) if len(i) > 1: stri = "st " stri = stri + str(i[0]) + ", " for j in i: if j != i[0]: stri = stri + str(j) + " " strt = stri[-3:] if ',' not in strt: fo.write(stri + "\n") fo.close() def Compact2(L): for i in range(len(L)): x = L[-i - 1] for j in range(len(L)): y = L[j] if y[0] in x and x[0] > y[0]: L[-i - 1].remove(y[0]) if x[0] not in L[j]: L[j].append(x[0]) L = [sublist for sublist in L if sublist != []] for i in range(len(L)): t = 0 v = [] x = L[i] for j in range(len(L)): r = L[j] if i != j and len(r) > 0 and r[0] in x: t = t + 1 v.append(j) if t == len(x) - 1: for k in v: if x[0] not in L[k]: L[k].append(x[0]) L[i] = [] L = [sublist for sublist in L if sublist != []] Filewrite(L)