day1/exercise/kwfreq.py
changeset 64 333092b68926
child 86 f657495cf8b2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/day1/exercise/kwfreq.py	Thu Oct 08 18:59:47 2009 +0530
@@ -0,0 +1,14 @@
+import keyword
+f = open('/home/madhu/pyprogs/pytriads.py')
+
+freq = {}
+for line in f:
+    words = line.split()
+    for word in words:
+        key = word.strip(',.!;?()[]: ')
+        if keyword.iskeyword(key):
+            value = freq.get(key, 1)
+            freq[key] = value + 1
+
+print freq
+