|
|
@ -17,14 +17,12 @@ def frequencies(word_list):
|
|
|
|
def sort(word_freq):
|
|
|
|
def sort(word_freq):
|
|
|
|
return sorted( word_freq.items(), key=lambda x: x[1], reverse=True )
|
|
|
|
return sorted( word_freq.items(), key=lambda x: x[1], reverse=True )
|
|
|
|
|
|
|
|
|
|
|
|
def printall(word_freqs, n = 10 ):
|
|
|
|
|
|
|
|
for word, freq in word_freqs[ :n ]:
|
|
|
|
|
|
|
|
print(word, '-', freq)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|
txtcontent = read_file( testfilepath )
|
|
|
|
txtcontent = read_file( testfilepath )
|
|
|
|
word_list = extractwords( txtcontent )
|
|
|
|
word_list = extractwords( txtcontent )
|
|
|
|
word_freqs = frequencies( word_list )
|
|
|
|
word_freqs = frequencies( word_list )
|
|
|
|
word_sort = sort ( word_freqs )
|
|
|
|
word_sorts = sort ( word_freqs )
|
|
|
|
printall(word_sort)
|
|
|
|
|
|
|
|
|
|
|
|
for tf in word_sorts[:10]:
|
|
|
|
|
|
|
|
print(tf[0], '-', tf[1])
|