summaryrefslogtreecommitdiff
path: root/day1/exercise/kwfreq.py
blob: e905e266da6ef20cc2bb6c9b2d8837f20a61d932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import keyword
f = open('amicable.py')

freq = {}
for line in f:
    words = line.split()
    for word in words:
        key = word.strip(',.!;?()[]: ')
        if keyword.iskeyword(key):
            if key in freq:
                freq[key] += 1
            else:
                freq[key] = 1

print freq