SECTION 30 / 31
Debug the first occurrence, the repeated key and empty input

Trace tiny inputs before processing the whole dataset. Use no records, one record, the same group twice, a missing key, a stored zero, and two different records with a shared name. Decide whether the algorithm counts occurrences or unique IDs. Test the key and value types separately.
| Mistake | Effect | Fix |
|---|---|---|
| d[k]=d[k]+1 before a first occurrence | Reads an absent value | Create 1, or create 0 then increment |
| d[k]=1 on every occurrence | Erases the accumulated count | Increment when present |
| inner dictionary={} on every row | Loses previous inner keys | Initialize only for a new outer key |
| Assume keys(d) is sorted | Order-dependent result can fail | Sort the key list explicitly when required |
| Use −1 as a real word position | Wrong word access | Check sentinel before looking up a word |
| Count names instead of unique student IDs | Can overwrite records | Choose a unique key or group records deliberately |
Try it yourself
What tiny input catches overwriting a frequency with 1?
Show explained answer
Two records with the same key. The expected frequency is 2, not 1.
Try it yourself
What catches an unguarded average?
Show explained answer
An empty dictionary, where count is 0.
Try it yourself
What catches a pronoun matcher that forgets its sentinel?
Show explained answer
A pronoun with no preceding noun, such as the first word of the supplied paragraph.
