I wont to find most 10 frequency word of specific file for that I have written this code
import sys
import string
import re
file = open ( "corpora.txt", "r" )
text = file.read ( )
file.close ( )
word_freq ={ }
word_list = string.split ( text )
for word in word_list:
count = word_freq.get ( string.lower ( word ), 0 )
word_freq[string. lower ( word )] = count + 1
keys = word_freq.keys ( )
keys.sort ( )
i=0
while i<10:
for word in keys:
print word, word_freq[word]
i=1+1
but it only get the word and its frequency
sample output
blanklines 2
blanklines, 1
characters 1
console 1
count 3
blanklines 2
blanklines, 1
characters 1
console 1
count 3
and its read the file again and again. also it did not sort the
output as you can see
how I can sort output in decrease order to be able to stop print after 10 words?
please help me ASAP