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 8038797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:21:21+00:00 2026-06-05T03:21:21+00:00

I was writing a program for averaging some values. Details: I was having a

  • 0

I was writing a program for averaging some values. Details: I was having a folder and within which I got many .txt files with float numbers.
All I was doing is summing up the float values and storing them in a Counter for each files.
After that I want to add up all values in the Counter and divide them by total no. of files(i.e..txt).

But up to storing in a Counter goes fine, but when I want add up the values present in the Counter by using sum(Counter.values()) then it raises an error showing 'float' object has no attribute 'values'
I have gone through the manuals also, they are also saying it is possible for integer values.
But is there any was to add up float values within a counter.

  • 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-05T03:21:24+00:00Added an answer on June 5, 2026 at 3:21 am

    Why are you using a Counter object for summing values in files? Its stated purpose is “for counting hashable objects” (i.e. if you have multiple discrete objects that you want to count instances of).

    If you want to store a sum floating point values from each file, try a regular dictionary:

    floatsums = {}
    floatsums['file1.txt'] = ... // insert code to sum the floats
    
    total = sum(floatsums.values())
    numfiles = len(floatsums)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing program which translate Pascal to C and need some help. I started
I'm writing a program with a lot of enumerations, and I'm having to return
I am writing a program and have some code inside a string. This code
I have been writing a program which asks you to input two integers, which
I'm writing a program which creates a large number of large arrays to store
Writing a program in which I need to split strings from a struct linked
I am writing a program which will type a line of text in 5
Good day! I have met problem with synchronizing threads. I am writing program which
I'm writing a program which talks to a SOAP API. The program I'm writing
I'm writing a program that will watch a particular directory for new files containing

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.