any way to tackle float Counter values in python -
i writing program averaging values. details: having folder , within got many .txt files float numbers.
doing summing float values , storing them in counter each files.
after want add values in counter , divide them total no. of files(i.e..txt).
but storing in counter goes fine, when want add values present in counter using sum(counter.values()) raises error showing 'float' object has no attribute 'values'
have gone through manuals also, saying possible integer values.
there add float values within counter.
why using counter object summing values in files? stated purpose "for counting hashable objects" (i.e. if have multiple discrete objects want count instances of).
if want store sum floating point values each file, try regular dictionary:
floatsums = {} floatsums['file1.txt'] = ... // insert code sum floats total = sum(floatsums.values()) numfiles = len(floatsums)
Comments
Post a Comment