Determination of relatively frequency distribution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # Created by Doni Ganchev, ganchevdoni@gmail.com
s=[0,0,0,1,2,2,3,4]
y0=0
y1=0
y2=0
y3=0
y4=0
for x in s:
if x==0:
y0=y0+1
if x==1:
y1=y1+1
if x==2:
y2=y2+1
if x==3:
y3=y3+1
if x==4:
y4=y4+1
print y0
print y1
print y2
print y4
|
-1: It would be much cleaner, general, and concise to hold the results in a dictionary, and to remove all the tests:
You probably want to have a look at collections.Counter.