day1/exercise/kwfreq.py
changeset 64 333092b68926
child 86 f657495cf8b2
equal deleted inserted replaced
63:f5eac04a00fe 64:333092b68926
       
     1 import keyword
       
     2 f = open('/home/madhu/pyprogs/pytriads.py')
       
     3 
       
     4 freq = {}
       
     5 for line in f:
       
     6     words = line.split()
       
     7     for word in words:
       
     8         key = word.strip(',.!;?()[]: ')
       
     9         if keyword.iskeyword(key):
       
    10             value = freq.get(key, 1)
       
    11             freq[key] = value + 1
       
    12 
       
    13 print freq
       
    14