Question: Python: Create a new function called score_sentence which takes in two arguments: a string representing a sentence, and a score dictionary. It should then take
Python: Create a new function called score_sentence which takes in two arguments: a string representing a sentence, and a score dictionary. It should then take the unique words in the sentence and output a score for the sentence by summing the corresponding score from the dictionary for each word. If the word is not in the dictionary, the corresponding value should be 0.
Example:
my_sentence = "Welcome, welcome to my house!" scores = {'welcome': 0.5, 'house': -0.25} final_score = score_sentence(my_sentence, scores) # Should output 0.25
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
