I have the code which will throw the output from the given string.
inputdata = "HELLO HELLO HELLO BOBBY WHAT ARE YOU DOING"
myDict = {}
linenum = 0
for word in inputdata.split():
if not word in myDict:
myDict[word] = []
myDict[word].append(linenum)
print "%-15s %-15s" %("Word", "Frequency")
for key in sorted(myDict):
print '%-15s: %-15d' % (key, len(myDict[key]))
the output would be
Word Frequency
ARE : 1
BOBBY : 1
DOING : 1
HELLO : 3
WHAT : 1
YOU : 1
But when I tried to replace the string with .txt file, Script was prompting the popup to enter the text instead of reading the data from the .txt file.
f = open(raw_input("eng.txt"), "r")
myDict = {}
linenum = 0
for word in f.split():
if not word in myDict:
myDict[word] = []
myDict[word].append(linenum)
print "%-15s %-15s" %("Word", "Frequency")
for key in sorted(myDict):
print '%-15s: %-15d' % (key, len(myDict[key]))