day1/debug_exercise.py
author prabhu@localhost
Fri, 09 Oct 2009 22:57:00 +0530
changeset 93 27b67b50280b
parent 86 f657495cf8b2
permissions -rw-r--r--
ENH: Fixing compile errors and removing CDEEP.
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