import os import json tyyp="PER" fnimed=os.listdir("vastused_failiti_koos") v={} for fnimi in fnimed: print(fnimi) fsisu=open("vastused_failiti_koos/"+fnimi, encoding="utf-8").readlines(); fsisu=[rida.strip() for rida in fsisu if len(rida)>3] for rida in fsisu: m=rida.split(",") if m[0]==tyyp: if m[1] in v: v[m[1]].append(fnimi) else: v[m[1]]=[fnimi] json.dump(v, open(tyyp+"sonastik.json", "w", encoding="utf-8"), ensure_ascii=False)