m=open("C1_bigrammid.csv", encoding="utf-8").readlines() def sorteerija(rida): r=rida.split(";") if len(r[1])<5: return "" return r[1].split()[1]+r[2].split()[1] m.sort(key=sorteerija) f2=open("c1sort.csv", "w", encoding="utf-8") print("".join(m), file=f2) f2.close()