Suppose we have a data set, ls=(0.3,1.4,1.6,2.3,3.2,4.7) Find the count of values within intervals of 2. I have to implement this functionality in python whose c code looks like this:
count[length(ls)]={0};
limit=2;
j=0;
for (i=0;i<length(ls);i++)
{
if(ls[i]<limit)
count[j]+=1;
else
{
j++;
i=i-1;
limit+=2
}
}
This is our implementation in python
for i in range(limit,10,limit):
count=0
for j in ls:
if j<i+limit and j>i:
print j,
count=count+1
elif j<i:
pass
else:
break
please suggest an optimized solution
Thanks in advance