Setdefault

Report a typo

Suppose we have the following short sentence and an empty dictionary:

sentence = 'Chess set is a chessboard and a set of chessmen.'
frequencies = {}

Now, we want to calculate the frequencies for each word in this sentence with the help of the dict.setdefault(). Put the steps below in the correct order.

Reorder lines using drag or arrows. Adjust indentation with left buttons
                frequencies.setdefault(word, 0)
              
                frequencies[word] += 1
              
                for word in sentence_list:
              
                sentence_list = sentence.lower().split()
              
                print(frequencies['chess'])
              
___

Create a free account to access the full topic