day1/exercise/kwfreq.py
author Puneeth Chaganti <punchagan@fossee.in>
Fri, 09 Oct 2009 12:55:34 +0530
changeset 84 338b85a9c864
parent 64 333092b68926
child 86 f657495cf8b2
permissions -rw-r--r--
Minor edits to Session2 Day2.

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