-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy path23.py
More file actions
21 lines (16 loc) · 774 Bytes
/
23.py
File metadata and controls
21 lines (16 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# The name of the California school with the highest number of girls enrolled in kindergarten, according to the CA Dept. of Education's latest enrollment data file.
import csv
import requests
from collections import defaultdict
from operator import itemgetter
url = 'http://dq.cde.ca.gov/dataquest/dlfile/dlfile.aspx?cLevel=School&cYear=2014-15&cCat=Enrollment&cPage=filesenr.asp'
def foo(row):
return int(row['KDGN']) if row['KDGN'] else 0
lines = requests.get(url).text.splitlines()
data = list(csv.DictReader(lines, delimiter = "\t"))
codes = defaultdict(int)
for d in data:
if d['GENDER'] == 'F':
codes[d['CDS_CODE']] += int(d['KDGN'])
cds, num = max(codes.items(), key = itemgetter(1))
print([d['SCHOOL'] for d in data if d['CDS_CODE'] == cds][0])