from collections import defaultdict import urllib.request marksonad={} ryhmasonad=set() for rida in open("marksonad.csv", encoding="utf-8"): m=rida.strip().split(",") marksonad[m[0]]=m[1] m0=urllib.request.urlopen("https://minitorn.tlu.ee/~jaagup/oma/too/23/05/word2vec/vastused/jaotus1000_marksonad.txt").read().decode("utf-8").split("\n") f2=open("jaotus1000_lisa.txt", "w", encoding="utf-8") for nr in range(1000): print(m0[nr*3].strip(), file=f2) print(m0[nr*3+1].strip(), file=f2) kogused=defaultdict(int) for sona in m0[nr*3+1].strip().split(): if sona in marksonad: kogused[marksonad[sona]]+=1 print(kogused, file=f2) print(file=f2) f2.close()