I have a binary list of 20 numbers : a=[1,1,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1,0,0,0,1,1,1,0,1,1,0,1,1,0], my goal is to count the maximum number of consecutive occurrences of 1 on each 5 elements and store it on a list, in this case the output would be: out= [4,5,3], because on the first 10 elements we have 4 consecutive 1s as a maximum, and on the second 10 elements we have 5 consecutive 1s and the last we have 3.
My current function is the following:
`def count_ones(lista):
counts=[]
longest=0
current=0
for n in range(0,len(lista),10):
for i in range(n,n+10):
if i>= len(lista): break
if lista[i]==1:
current+=1
else:
longest= max(longest , current)
current=0
counts.append(longest)
return (counts)
`
which is not working properly