Question: Write a function named count_words that takes a string named my_string and returns a dictionary where the keys in the dictionary are the words in
- Write a function named count_words that takes a string named my_string and returns a dictionary where the keys in the dictionary are the words in my_string and values are the number of times that each word appears in my_string.
For example: my_string = I waited for the train but the train was late count_words(my_string) Output should be this dictionary: {'i': 1, 'waited': 1, 'for': 1, 'the': 2, 'train': 2, 'but': 1, 'was': 1, 'late': 1}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
