day1/exercise/kwfreq.py
author Puneeth Chaganti <punchagan@fossee.in>
Thu, 09 Dec 2010 23:11:12 +0530
branchscipyin2010
changeset 448 dc8d666a594a
parent 380 669b72283b55
permissions -rw-r--r--
Changed date format in day1/session{3,4,5}.tex.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
freq = {}
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
for line in f:
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
    words = line.split()
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
    for word in words:
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
        key = word.strip(',.!;?()[]: ')
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
        if keyword.iskeyword(key):
180
e442b9e23972 Made English and low level id changes to session1.tex
rivermaker@RivermakerMBP.local
parents: 86
diff changeset
     7
            if key in freq:
e442b9e23972 Made English and low level id changes to session1.tex
rivermaker@RivermakerMBP.local
parents: 86
diff changeset
     8
                freq[key] += 1
e442b9e23972 Made English and low level id changes to session1.tex
rivermaker@RivermakerMBP.local
parents: 86
diff changeset
     9
            else:
e442b9e23972 Made English and low level id changes to session1.tex
rivermaker@RivermakerMBP.local
parents: 86
diff changeset
    10
                freq[key] = 1
64
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
print freq
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13