Question: 3 Write a function named top k words which take one string and one integer as input. This function should return the k most frequent

3 Write a function named top k words which take one string and one integer as input. This function should return the k most frequent words. Your answer should be sorted by frequency from highest to lowest.

3.1 Assumptions You may assume input string only contains lowercase alphabets, punctuation, spaces. You may assume k is always valid You may assume no two words have same frequency 2

3.2 Examples Input: "i love python, he love coding python; the course is about python.. " k = 2 Output: [python, love] Explanation: "python" and "love" are the two most frequent words.

3.3 Function requirement function name: top_k_words input :String s, Integer k output: List of String

3.4 Hint 1. Try to get a clean string (with only space separated). One way to do this is to copy only characters and valid spaces to a new place 2. Then try to split string into one list 3. Get top k words

Please use python thank you

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!