Count the words that matter
A support tool skims ticket text to see which terms keep coming up, ignoring the little joining words.
- Split on whitespace and compare in lowercase.
- Words shorter than three characters are noise and are left out.
- The result maps each remaining word to how many times it appeared.
word_frequency(text: string) → map<string, int>
Where you start
def word_frequency(text: str) -> dict[str, int]:
Worked examples
| Call | Result |
|---|---|
word_frequency("card declined card") | {"card": 2, "declined": 1} |
word_frequency("The the THE") | {"the": 3} |
word_frequency("a an I ok") | {} |
word_frequency("") | {} |
Hint
Lowercase before counting, or "Payment" and "payment" end up as two entries.
Reference solution in Python
def word_frequency(text: str) -> dict[str, int]:
result = {}
for w in text.lower().split():
if len(w) < 3:
continue
result[w] = result.get(w, 0) + 1
return result