day1/exercise/kwfreq.py
author Shantanu <shantanu@fossee.in>
Thu, 08 Oct 2009 23:16:13 +0530
changeset 76 b24c2560f626
parent 64 333092b68926
child 86 f657495cf8b2
permissions -rw-r--r--
Added links.tex, compilation of various links.

import keyword
f = open('/home/madhu/pyprogs/pytriads.py')

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

print freq