I have a list of 0s and 1s and I want to know how often 0 occures successively. I wrote a quick and dirty solution. However, I believe it is slow
For example
a = [0,0,0,1,1,1,0,0,0,1,1,0,0]
def duration(a):
b = "".join([str(x) for x in a])
return [len(x) for x in b.split("1") if len(x)>0]
print(duration(a))
gives the correct output ([3,3,2]). I am convinced that there is a much faster way of doing it.
Thanks,
glostas