day1/debug_exercise.py
author Santosh G. Vattam <vattam.santosh@gmail.com>
Fri, 09 Oct 2009 17:04:07 +0530
changeset 92 d9c31aacd835
parent 86 f657495cf8b2
permissions -rw-r--r--
Made little changes to handout.tex.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
     1
import keyword
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
     2
f = open('/path/to/file')
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
     3
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
     4
freq = {}
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
     5
for line in f:
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
     6
    words = line.split()
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
     7
    for word in words:
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
     8
        key = word.strip(',.!;?()[]: ')
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
     9
        if keyword.iskeyword(key):
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
    10
            value = freq[key]
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
    11
            freq[key] = value + 1
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
    12
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 30
diff changeset
    13
print freq