Interview Query

Word Frequency

Start Timer

0:00:00

Upvote
13
Downvote
Save question
Mark as completed
View comments (17)
Next question

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.

Note: Due to limitations with our code runner, your keys will be displayed as strings instead of integers. But you do not need to convert the keys to strings yourself

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"]
}
.
.
.
.
.


Comments

Loading comments