Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago