changeset 180 | e442b9e23972 |
parent 86 | f657495cf8b2 |
child 380 | 669b72283b55 |
--- a/day1/exercise/kwfreq.py Tue Oct 27 10:59:11 2009 +0530 +++ b/day1/exercise/kwfreq.py Tue Oct 27 11:58:55 2009 +0530 @@ -1,5 +1,5 @@ import keyword -f = open('/path/to/file') +f = open('amicable.py') freq = {} for line in f: @@ -7,8 +7,10 @@ for word in words: key = word.strip(',.!;?()[]: ') if keyword.iskeyword(key): - value = freq[key] - freq[key] = value + 1 + if key in freq: + freq[key] += 1 + else: + freq[key] = 1 print freq