import os import json 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] v[fnimi]={"PER":[], "ORG":[], "LOC":[]} for rida in fsisu: m=rida.split(",") v[fnimi][m[0]].append(m[1]) json.dump(v, open("fsonastik.json", "w", encoding="utf-8"), ensure_ascii=False)