day1/debug_exercise.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Fri, 09 Oct 2009 12:59:55 +0530
changeset 86 f657495cf8b2
parent 30 3e21614218f4
permissions -rw-r--r--
Final set of changes.
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