I’m making a function which takes as input (string, dict) and returns a float. The function accepts as input the text from a file to evaluate and the dictionary for individual words. The function must return the score for the text as a whole. That is, the score is the average of the score of words which appear.
I have a .csv file with a list of words each given a score and std deviation. In the file each line takes the form
word{TAB}score{TAB}standard_deviation
I’m making the letters all lower case and attempting to take the average of all the scores.
I have this so far but can’t figure out with correct method to get the average:
def happiness_score(string , dict):
sum = 0
for word in string:
dict = dict()
if word in dict:
sum += word
word = string.lower()
word,score,std = line.split()
d[word]=float(score),float(std)
return sum/len(dict)
im not sure of the exact mathematical operation you want to perform.
and im not sure if you are able to read the file or not.
but hopefully this will provide some guidance.