-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_dict.py
More file actions
25 lines (23 loc) · 826 Bytes
/
get_dict.py
File metadata and controls
25 lines (23 loc) · 826 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
from typing import Dict
import csv
def load_dict(filename: str) -> Dict:
"""Create a dictionary
"""
d = {}
with open(filename, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
try:
if row['health_region'] not in d:
d[row['health_region']] = {'cases': 1, \
'latitude': float(row['latitude']), \
'longitude': float(row['longitude'])}
else:
d[row['health_region']]['cases'] += 1
except ValueError: # no longitude nor latitude
pass
return d
if __name__ == '__main__':
d = load_dict('server\COVID19_case_details.csv')
for key in d:
print(f'{key}: {d[key]}')