14
Question Question 11(a)
Find the errors:
text = "abracadbra"
counts = {}
for word in text :
counts[word] = counts[word] + 1Output
KeyError: 'a'
Explanation
The line counts[word] = counts[word] + 1 will cause a KeyError because we are trying to access a key word of an empty dictionary. As the key is not present in dictionary counts, hence a KeyError is generated.