Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions