I need to be able to store data, one being a number and one being the number of times it appeared. I have a for loop that calls a method that returns a dictionary:
for x in range(total_holidays):
t = trial()
y = y + "\n" + str(x+1) + "," + str(t["brown"]) + "," + str(t["rainbow"]) + "," + str(t["nothing"]) + "," + str(t["days"])
total += t["days"]
#print total
if x%10000 == 0:
y0.append(y)
y = ""
Basically I need to count how many times t[‘days’] happens, the number changes almost every time. If you want the full code look here:
So how would I do this and then I need to print it all out after.
y is text for a csv file, and total is used to calculate the average.
As suggested by mgilson should I use this?
from collections import Counter
a = []
for x in range(total_holidays):
t = trial()
y = y + "\n" + str(x+1) + "," + str(t["brown"]) + "," + str(t["rainbow"]) + "," + str(t["nothing"]) + "," + str(t["days"])
total += t["days"]
a.append(t['days'])
#print total
if x%10000 == 0:
y0.append(y)
y = ""
z = Counter(a)
print z
Should I have something like that?
What you want is the
collections.Countertype, adictsubtype specialized for this kind of task: