-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask22.py
42 lines (32 loc) · 852 Bytes
/
task22.py
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
37
38
39
40
41
42
import csv
import collections
def max_crime(crimes):
max = -1
type = ''
for key in crimes:
crime = key
count = crimes[key]
if count > max:
max = count
type = crime
return type
def get_date(crime): # crime – dictionary
date = crime['Date'][6:10]
return date
crimes = {}
with open('Crimes.csv') as f:
file = csv.DictReader(f)
for row in file:
crime = row['Primary Type']
date = get_date(row)
if date == "2015":
if crime in crimes:
crimes[crime] += 1
else: # new type of crime
crimes[crime] = 1
answer = max_crime(crimes)
print(answer)
# for i, row in enumerate(file):
# print(row)
# if i >= 10:
# break