day1/exercise/kwfreq.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Wed, 14 Oct 2009 20:40:35 +0530
changeset 120 055b199c46c2
parent 86 f657495cf8b2
child 180 e442b9e23972
permissions -rw-r--r--
Added NumPy array operations to session3 day1 for sslc1.txt.

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