Write a function called most_common_word that takes a phrase as input and returns the most common word in the phrase. If multiple words are equally common then return the first word alphabetically.
Example:
>>> phrase = "she sells sea shells by the sea shore"
>>> unique_words(phrase)
['by', 'sea', 'sells', 'she', 'shells', 'shore', 'the']
>>>count_word(phrase, 'sea') 2
>>>count_all_words(phrase) [['by', 1],
['sea', 2], ['sells', 1], ['she', 1], ['shells', 1], ['shore', 1], ['the', 1]]
>>>most_common_word(phrase) 'sea'
Python Script for ATOM or REPL, (NOT SHELL)
RAW CODE
phrase = "she sells sea shells by the sea shore"
def most_common_word(data):
data = data.split()
frequency = {}
for word in data:
frequency[word] = data.count(word)
return max(sorted(frequency),key=frequency.get)
print(most_common_word(phrase))
SCREENSHOT (CODE AND OUTPUT)
##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####
Get Answers For Free
Most questions answered within 1 hours.