Python Practice Lab
easyUnit 7 · Dictionaries & Sets

P19. Word Frequency

Dictionaries & Sets

Read a sentence of lowercase words. Count how many times each word appears, using a dictionary, with the words in order of first appearance. Then print the most frequent word (the first one in that order if there is a tie).

Input Format

  • Line 1: lowercase words separated by spaces

Output Format

  • Line 1: Frequency: <dict>
  • Line 2: Most frequent: <word>

Constraints

  • 1 ≤ number of words ≤ 100

Sample Test Cases

Sample 1
Input
the cat and the dog and the bird
Output
Frequency: {'the': 3, 'cat': 1, 'and': 2, 'dog': 1, 'bird': 1}
Most frequent: the
Sample 2
Input
hello
Output
Frequency: {'hello': 1}
Most frequent: hello

Submitting checks 2 sample cases and 3 hidden test cases.

Hints

Saved
Custom 1

This is your own input, so Run will show what your program prints but can't say whether it's correct.