I am trying to find most frequent words in a text file in alphabetical order in this different program.
For example, the word: "that" is the most frequent word in the text file. So, it should be printed first: "that #"
It needs to be in this type of format as the program and as the answer below:
d = dict()
def counter_one():
d = dict()
word_file = open('gg.txt')
for line in word_file:
word = line.strip().lower()
d = counter_two(word, d)
return d
def counter_two(word, d):
d = dict()
word_file = open('gg.txt')
for line in word_file:
if word not in d:
d[word] = 1
else:
d[word] + 1
return d
def diction(d):
for key, val in d.iteritems():
print key, val
counter_one()
diction(d)
It should run something like this in the shell:
>>>
Words in text: ###
Frequent Words: ###
that 11
the 11
we 10
which 10
>>>