Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Counting words in a string Write a function word_counter (input_str) which takes a string input_str and returns a dictionary mapping words in input_str to their
Counting words in a string Write a function word_counter (input_str) which takes a string input_str and returns a dictionary mapping words in input_str to their occurrence counts. The keys must be inserted into the dictionary in the order in which they occur in the input string You may assume for this question that the list of words in input_str is just input_str.split) except that words must be converted to lower case at some point. For example Test Result word_count_dict word_counter("This is a sentence this is") 'this': 2, is:2, 'a': 1, sentence': 1) print(word_count_dict) ecord count_dict word-counter("AMORD is print (word_count_dict) word it is") {.a': 2, .uord.: 2, .is: 2, .it': 1}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started