Skip to main content
🐍 Python Projects

Word Counter

What you're building

A WordCounter class that parses a block of text, counts every word (case-insensitive, no punctuation), and reports statistics.

Requirements

  • count_words() β€” total word count
  • unique_count() β€” number of distinct words
  • top_word() β€” the single most frequent word (lowercase)
wc = WordCounter("The cat sat on the mat. The cat!")
wc.count_words()   # 8
wc.unique_count()  # 5
wc.top_word()      # "the"

Stretch goals

  • Handle ties in top_word by returning the alphabetically first word.
  • Add frequency(word) that returns the count for a specific word.

What this proves

String manipulation, dictionaries for counting, and basic class design β€” all staples of data-wrangling interviews.

⚑ 40 XP
solution.pyRuns in your browser (Pyodide)
Loading editor…
Tests4 to pass
count_words totals all words
unique_count counts distinct words
top_word returns most frequent
case-insensitive: The == the

Run your code to check these.