#!/usr/bin/python words = {} f = open('ocap.txt','r') for line in f: for word in line.split(): # I am sure that there is a better way to do this, # but it might depend on the version of python. tmp = "" for letter in word.lower(): if letter >= 'a' and letter <= 'z': tmp = tmp + letter word = tmp if word in words: words[word] +=1 else: words[word] = 1 print words count = 0; for key in words.keys(): if words[key] > count: count = words[key] print "Most frequent word appears ", count, 'times' for key in words.keys(): if words[key] == count: print key # a tiny bit of googling to get this import operator for item in sorted(words.items(), key=operator.itemgetter(1)): print "%15s"%item[0],": ","%4d"% item[1]