day1/exercise/kwfreq.py
author Puneeth Chaganti <punchagan@fossee.in>
Mon, 26 Oct 2009 20:44:54 +0530
changeset 177 4ec0418ba041
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