forked from edooley7/dsp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced_python_regex.py
More file actions
36 lines (30 loc) · 1.03 KB
/
advanced_python_regex.py
File metadata and controls
36 lines (30 loc) · 1.03 KB
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
from collections import defaultdict
import csv
csvFilename = 'faculty.csv'
ddeg = defaultdict(int)
dtitle = defaultdict(int)
emails = []
domains = set()
csv.register_dialect('whitespace', delimiter=',', skipinitialspace=True)
with open(csvFilename) as fin:
rdr = csv.DictReader(fin, dialect='whitespace')
for row in rdr:
deg = row['degree'].translate(None, '.')
ddeg[deg] += 1
dtitle[row['title']] += 1
email = row['email']
emails.append(email)
ed = email.split('@')
domains.add(ed[1])
print "Q1. There are %d different degrees with frequenices:<br/>" % len(ddeg)
for key, value in ddeg.iteritems():
print key, ':', value, '<br/>'
print "Q2. There are %d different titles with frequenices:<br/>" % len(dtitle)
for key, value in dtitle.iteritems():
print key, ':', value, '<br/>'
print "Q3. Email addreses are:<br/>"
for email in emails:
print email, '<br/>'
print "Q4. There are %d different email domains:<br/>" % len(domains)
for value in domains:
print value, '<br/>'