CJCoding With Joseph
15free / daySign inCreate account

Count Words In A List

Count how many times each word appears in the list words. Loop over the list with a dict of counts: use in to check whether the word is already a key, add one to its count if so, otherwise store it with a count of 1. Then loop over the dict and print one line per distinct word in the form <word> <count>, in the order the words were first seen. Input: none. Output: one line per distinct word.

Expected Output:

tea 3
milk 2
sugar 1

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
Dictionaries
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.