I have a list of binary values: 1 = syncable, 0 =unsyncable. Each binary value represents whether or not a person was syncable that day.
person1=[1,1,0,1,1,0,1,1,1]
I want to make another list, calculating how many days a person was syncable consecutively. When a 0 appears, the counter basically resets.
So for the example above, the output would look like:
person1=[1,2,0,1,2,0,1,2,3]
My issue is whenever the list comes across a 0. I don't know how to get it to reset. I've tried several ways, none of which works.
x=[1,1,1,1,1]
y=[]
for index, value in enumerate(x):
y.append(value+sum(x[:index]))
print(y)
...
[1, 2, 3, 4, 5]
Any help is appreciated. I think using recursion might help.