User:Ozalp Eroz/3.assignment

From XPUB & Lens-Based wiki
import codecs 
t=codecs.open("text.txt", "r", "utf-8").read()
#print t

import re
words=re.findall(r"\b[a-z']+\b",t ,re.I)
#print words

count = {}

for w in words:
    
    if not w in count :
        #store a 1 under the word
        count[w]=1
    else:
        #add 1 to the word
        count[w]+=1


from pprint import pprint

keys = count.keys()
keys.sort()

for (words, count) in count.items():

    print "<span style='font-size: "+str(count)+"0px'>",
    print words, count
    print "</span>"
    print "<span style='font-size: %d0px'>%s</span>" % (count, words),
    print "<span style='font-size: {{1}}0px'>{{2}}</span>".format(count, words),


python count.py > count.html
firefox count.html