day1/exercise/kwfreq.py
author Puneeth Chaganti <punchagan@fossee.in>
Mon, 26 Oct 2009 19:48:59 +0530
changeset 173 c3acf025db80
parent 86 f657495cf8b2
child 180 e442b9e23972
permissions -rw-r--r--
Merged with mainline.

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