day1/exercise/kwfreq.py
author Puneeth Chaganti <punchagan@fossee.in>
Mon, 12 Oct 2009 12:09:16 +0530
changeset 98 1b9a427f41c6
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