Get Top N Frequent Words
Start Timer
0:00:00
Given an example paragraph string and an integer
N, write a functionn_frequent_wordsthat returns the topNfrequent words in the posting and the frequencies for each word.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