Word Frequency
Completed
Read a line of words and print each distinct word with its count, in order of first appearance, as word count.
Input
One line.
Output
One line per distinct word.
Example
Input
to be or not to be
Output
to 2 be 2 or 1 not 1
Editor
Python
Hints
counts.get(w, 0) + 1 increases a count, starting from 0.
Dictionaries remember insertion order.
Solution explanation
Since Python 3.7 dicts keep insertion order, so iterating gives first-appearance order.
Show solution
counts = {}
for w in input().split():
counts[w] = counts.get(w, 0) + 1
for w, c in counts.items():
print(w, c)