Spring Deals - hours only!Up to 70% off on all courses and bundles.-Close
Dictionary basics
Dictionaries in loops and conditional statements
11. Additional practice
Dictionaries in functions


Great! Let's do one more exercise here.


Write a program that will ask the user for a string value.

Next, create a dictionary named word_frequencies. The dictionary should contain all unique words from the user input as keys, and their frequencies (number of occurrences in the string) as values.

To iterate over words in Python, you can use:

for word in user_input.split():

The split() function is important here. It splits the user-provided string into a list of individual strings using a space as the default separator. If you don't use the split() function, you'll iterate over characters instead.

Stuck? Here's a hint!

Start by creating an empty dictionary. For each word in the user input, if the given word is already in the dictionary, increase its value by 1. If the word is not yet in the dictionary, assign a value of 1 to it.