Get Top N Frequent Words

Start Timer

0:00:00

Upvote
28
Downvote
Save question
Mark as completed
View comments (32)
  1. Given an example paragraph string and an integer N, write a function n_frequent_words that returns the top N frequent words in the posting and the frequencies for each word.

  2. What’s the function run-time?

Example:

Input:

posting = """
Herbal sauna uses the healing properties of herbs in combination with distilled water.   
The water evaporates and distributes the effect of the herbs throughout the room.   
A visit to the herbal sauna can cause real miracles, especially for colds. 
"""  
n = 3

Output:

n_frequent_words(posting,N) = [
    ('the', 6), 
    ('herbal', 2), 
    ('sauna', 2),
]
.
.
.
.
.


Comments

Loading comments