Question: Python activity, very confused--any help is appreciated!! PART 1 Write a function called wordCollector that takes two parameters as input: 1) a dictionary (possibly an

Python activity, very confused--any help is appreciated!!

Python activity, very confused--any help is appreciated!! PART 1 Write a functioncalled wordCollector that takes two parameters as input: 1) a dictionary (possibly

PART 1 Write a function called wordCollector that takes two parameters as input: 1) a dictionary (possibly an empty dictionary) 2) a string representing a sentence. The function should iterate though the words in the sentence, and add them as keys to the dictionary, with the values representing the number of times the word has been seen. The function should first check to see if the word exists as a key in the dictionary. If the word is in the dictionary, then you should increment its count by one. If the word is not in the dictionary, then the function should add the word to the dictionary as a key, with a corresponding value 1, as an dictionary. Assume all the characters in the sentence are lowercase and there is no punctuation Hint for word in sentence. split will be helpful to iterate through the words Try the following code to test your implementation of wordCollector: empty dictionary word counts wordcounts wordCollector (wordcounts, this is a sentence") wordcounts word Collector (wordcounts this is like a group of words") wordcounts wordCollector (wordcounts lists of characters are this") for key in wordcounts: print key r wordcounts Ikey] If correctly implemented, you should see the following output: a 2 characters 1 group 1 like 1 sentence 1 this 3 of 2 is 2 lists 1 are words 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!