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