Skip to content

Instantly share code, notes, and snippets.

@Abdujabbar
Created May 6, 2016 13:44
Show Gist options
  • Save Abdujabbar/c32b3b01f8610be28f62b1e741f97ef2 to your computer and use it in GitHub Desktop.
Save Abdujabbar/c32b3b01f8610be28f62b1e741f97ef2 to your computer and use it in GitHub Desktop.
stepic python
import csv
import operator
from datetime import datetime
def validate_date(d):
try:
datetime.strptime(d, r'%m/%d/%Y %H:%M:%S %p')
return True
except ValueError:
return False
with open("Crimes.csv") as f:
reader = csv.reader(f)
c = 0
_dict = dict()
for line in reader:
if c == 0:
c += 1
continue
if validate_date(line[2]) and '2015' in line[2]:
if line[6] not in _dict.keys():
_dict[line[6]] = 1
else:
_dict[line[6]] += 1
__dict = sorted(_dict.items(), key=operator.itemgetter(1), reverse=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment