Question: def countWords(document): #This function counts the occurrence of every word in the string document #In today's version, you can assume document has no punctuation #e.g.

def countWords(document): #This function counts the occurrence of every word in the string "document" #In today's version, you can assume "document" has no punctuation #e.g. document = "He is vice president and he can be president", no period or commas #The function outputs a dictionary # whose keys are included words, in lower cases, and in alphabetical order # whose values are counts of the words #In the above e.g., # output = {'and': 1, 'be': 1, 'can': 1, 'he': 2, 'is': 1, 'president': 2, 'vice': 1} # #Complete the function following the comments and upload to Vocareum # ATTENTION!: upload just the complete function # with the function name countWords # and the file name EX6_16.py, # # ----- start the code here ------ #Split document into a list named "words", each element in lower case

#create an empty dictionary named "wordCounts"

#for each word in words, increment its count in the dictionary

#Sort the dictionary keys and put them into an extra list.

#create a dictionary wordcount2 with the keys sorted

#Return return wordCounts2

This is our python homework. I had some trouble to solve it. Please help me. Thank you very much!

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!