day1/exercise/kwfreq.py
author Santosh G. Vattam <vattam.santosh@gmail.com>
Thu, 15 Oct 2009 11:23:47 +0530
changeset 122 73374e1ae4f3
parent 86 f657495cf8b2
child 180 e442b9e23972
permissions -rw-r--r--
Merged branches.

import keyword
f = open('/path/to/file')

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

print freq