How to write a code in Python to read a text document and list words from most to least frequent? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to write a code in Python to read a text document and list words from most to least frequent?

the title says it all - I would like to analyze some books and make word (pattern in Python I suppose) statistics as an output. any idea how to do this?

9th Apr 2018, 9:36 PM
Adam Radivojevic
Adam Radivojevic - avatar
3 Answers
+ 5
Use the Counter module https://docs.python.org/2/library/collections.html You can input an array of the words and there’s a most_common method
9th Apr 2018, 9:50 PM
Ariela
Ariela - avatar
0
\ but wrong why?
10th Apr 2018, 3:44 AM
milton dio
milton dio - avatar
0
Thanks Ariela!
10th Apr 2018, 6:44 AM
Adam Radivojevic
Adam Radivojevic - avatar