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

  1. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!