Which Words Come Up Most?

Python for AIMedium+10 XP+10

Which Words Come Up Most?

Before training a text model, you often count how many times each word appears.

Task: write word_counts(text) that returns a dictionary mapping each word to how many times it appears.

  • Split the text on whitespace (any amount).
  • Count words ignoring case, and use the lowercase word as the key.
  • Punctuation stays part of the word, so "dog." and "dog" are different words.
  • Empty text gives {}.

Examples

text = "the cat and The dog"
returns {'the': 2, 'cat': 1, 'and': 1, 'dog': 1}
text = ""
returns {}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run