$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #158

Which fix removes the bug?

counts = {}
for word in words:
    counts[word] += 1
  1. Use counts.get(word, 0)
  2. Sort the words first
  3. Convert words to a set
  4. Initialise counts to zero
The first sighting of a word has no key yet, so += 1 raises KeyError.
Play Problem Solving ▸