From the course: Level Up: Python

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Count unique words

Count unique words - Python Tutorial

From the course: Level Up: Python

Count unique words

(game machine chimes) - Pretty much every modern word processor has a word count tool to count the total number of words in a document. For this challenge, we're going to take that tool one step further to practice both breaking down text and counting items. 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. An example call to the function might look like this. Printing out a message with the total word count and a top 20 list. How you choose to format that output is really up to you. You should ignore case when considering if two words are the same or different, and for this challenge, we'll say that words can…

Contents