kokku=165687818 plokkkokku=0 algus="" puhver=[] f2=open("plokid2.txt", "w") for rida in open("4gram_eest.txt"): if (algus!=rida[:3]): if "D" in algus: if algus: print(algus, plokkkokku, str(round(100*plokkkokku/kokku, 4))+"%", sep=",", file=f2) for prida in puhver: print(" "+prida[0], prida[1], str(round(100*prida[1]/plokkkokku, 2))+"%", sep=",", file=f2) algus=rida[:3] plokkkokku=0 puhver=[] m=rida.strip().split(",") puhver.append([rida[3], int(m[1])]) plokkkokku+=int(m[1]) if "D" in algus: print(algus, plokkkokku, str(round(100*plokkkokku/kokku, 4))+"%", sep=",", file=f2) for prida in puhver: print(" "+prida[0], prida[1], str(round(100*prida[1]/plokkkokku, 2))+"%", sep=",", file=f2) f2.close()