#!/usr/bin/env python import string def WordsOccur(): fileName = raw_input("Enter the name of the file: ") f=open(fileName,"r") wordList=string.split(f.read()) f.close() occursDict={} for word in wordList: occursDict[word] = occursDict.get(word, 0) +1 print "File %s has %d words (%d are unique)" \ % (fileName, len(wordList), len(occursDict) ) print occursDict if __name__ == '__main__': WordsOccur()