import json frequency=json.load(open("frequency.json", encoding="utf-8")) koikisonukokku=0 koiksonad={} for tase in frequency: for sona in frequency[tase]: koikisonukokku+=frequency[tase][sona]["frequencyCount"] if sona not in koiksonad: koiksonad[sona]={} for sona in koiksonad: sonakokku=0 for tase in frequency: if sona in frequency[tase]: koiksonad[sona][tase]=frequency[tase][sona] sonakokku+=frequency[tase][sona]["frequencyCount"] else: koiksonad[sona][tase]={"frequencyCount":0, "frequencyPercentage":0} koiksonad[sona]["kokku"]={"frequencyCount":sonakokku, "frequencyPercentage":round(100*sonakokku/koikisonukokku, 4)} with open("koiksonad.json", "w", encoding="utf-8") as f: json.dump(koiksonad, f)