我有一个数组,其值如下:
list1=[0,0,1,1,14,4,3,0,0,0,1,4,3]
我想找到该数组中 x > 0 的运行长度。所以输出将类似于:
runs = [5,3]
这是我到目前为止所拥有的,但不知道如何进行:
runs = []
curr = 0
for x in list1:
while x > 0:
curr += 1
#Not sure where to go from here. Somehow append curr to runs and
reset curr once the run is over
这是接近它的正确方法吗?