← Back to Dictionaries
Question 263
Word Frequency From Input
Word Frequency From Input
Count how often each word appears. Input: the first line is a whole number n, then n more lines with one word each; use range(n) to read them with a bare input(), no prompts. Keep the counts in a dict: when a word is already a key add one to its count, otherwise store it with a count of 1 (use in to check the key first). After all the words are read, print one line per distinct word in the order the words were first seen, in the form <word> <count> with one space between.
Expected Output:
apple 3 pear 1 fig 1
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
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.