day1/exercise/kwfreq.py
author Christopher Burns <chris.d.burns@gmail.com>
Wed, 16 Jun 2010 23:19:09 -0700
branchscipy2010
changeset 403 9b8f03e012ba
parent 380 669b72283b55
permissions -rw-r--r--
Add notes on day2 material for sessions 7-12
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