day1/exercise/kwfreq.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Thu, 08 Oct 2009 18:59:47 +0530
changeset 64 333092b68926
child 86 f657495cf8b2
permissions -rw-r--r--
Added quiz tex file and all exercise problems Madhu worked out.

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