PY-1

Count Repeated Words

  • Easy
  • Dictionaries
  • Python

Task

Write count_words(words). It must return a dictionary that records how many times each word appears in words.

words is a list of strings. It may be empty, and a word may appear once or many times. Treat strings with different spelling or capitalization as different words. Do not sort the input or change it.

Example

The first "cat" creates a count. The second one updates the same dictionary entry instead of creating another key.

Your implementation

Edit solution.py and keep this function name and signature:

Return a new dictionary. The keys must be the distinct words from the input, and each value must be that word's complete count. An empty input must return an empty dictionary. The input list must remain unchanged.

Do not use collections.Counter for this problem. Build the dictionary so the counting pattern remains visible.