Interview Query

Word Frequency

2
Have you seen this question before?

You’re hired by a literary newspaper for an unusual project. They want you to use your data science skills to parse the most frequent words used in poems.

Poems are given as a list of strings called sentences. Return a dictionary of the frequency that words are used in the poem.

Your keys should be a number representing the number of times the word is used in the poem, with its value being a list of words with that frequency.

Make sure to process all words as entirely lowercase. Additionally, do not worry about parsing punctuation marks.

Example:

Input:

sentences = [
  "I love roses",
  "Roses are the best",
  "Roses are red violets are blue"
]

Output:

def word_frequency(sentences) -> {
    1:["I","love","the","best","violets","blue"],
    3:["roses","are"]
}
Next question: Third Party Ad Pricing
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code