Your goal is to write a Python function that determines the number of unique words in a text file, and counts how many times each word occurs.
It should accept the path to a text file as the input argument, and then print the total number of words in the file, as well as the top 20 most frequently used words and how many times each of them occurs.
We'll say that words can contain letters, numbers, apostrophes and hyphens, and they're separated by any other punctuation or white space.
For e.g.
- from UniqueWords import unique_words
- unique_words('StanleyMullen.txt')
Total Worlds: 743
Top 20 words: AND 29 THE 29 A 26 WAS 15 TO 14 YOU 13 HE 12 OF 11 BRAUN 11 THERE 11 IN 11 ABOUT 11 IT 10 OUT 9 AS 9 I 8 HAD 7 INTO 7 TALK 6 ON 6
For testing purposes, grab sample text from https://www.gutenberg.org/ebooks/66572 to form your txt file. The Project Gutenberg eBook of The Voyage of Vanishing Men, by Stanley Mullen is a good starting point ( Date Accessed: Oct 19, 2021).