-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticule.py
More file actions
38 lines (29 loc) · 987 Bytes
/
particule.py
File metadata and controls
38 lines (29 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
from collections import Counter
cand=[]
candfin=[]
with open('par25.json') as json_data2:
data_dict2 = json.load(json_data2)
for e in data_dict2:
if((e["Nom"][0]+e["Nom"][1])=="DE" and e["Nom"][2]==" "):
cand.append(e["Candidat"])
print(Counter(cand).keys())
print(Counter(cand).values())
cand = list(set(cand))
for e in cand:
candfin.append([e,0])
with open('par25.json') as json_data2:
data_dict2 = json.load(json_data2)
for e in data_dict2:
if ((e["Nom"][0] + e["Nom"][1]) == "DE" and e["Nom"][2] == " "):
for a in candfin:
if(a[0]==e["Candidat"]):
a[1]+=1
sorted(candfin)
for i in candfin:
print(str(i[0])+ " : " + str(i[1]))
data=dict(candfin)
data ={k: v for k, v in sorted(data.items(), key=lambda item: item[1], reverse=True)}
print(data)
with open("particule.json", "w") as file:
json.dump(data, file, ensure_ascii=False)