Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8716307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:03:00+00:00 2026-06-13T06:03:00+00:00

I’m making a function which takes as input (string, dict) and returns a float.

  • 0

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:03:01+00:00Added an answer on June 13, 2026 at 6:03 am

    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.

    # to hold your variables
    holder_dict = {}
    
    # read the file:
    with open("/path/to/file.csv", 'r') as csv_read:
        for line in csv_read.readlines():
            word, score, std = line.split('\t')
            if word in holder_dict.keys():
                holder_dict[word][0] += [float(score)]
                holder_dict[word][1] += [std]
            else:
                holder_dict[word] = [[float(score)],[std]]
    
    # get average score
    for word in holder_dict.keys():
        average_score = sum(holder_dict[word][0])/len(holder_dict[word][0])
        print "average score for word: %s is %.3f" % (word, average_score)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.