Can\'t seem to find a clue to this online and can\'t figure it out myself so:
How would I go about slicing a list so that I return a list of slices of contiguous non
Here the very base solution you can try to use too:
data = [1, 0, 3, 7, 4, 1, 3, 7]
def get_zero_sliced(inputList):
res = []
prev = 0
for i,x in enumerate(data):
if x == 0 and i != 0:
res.append(data[prev:i])
prev = i + 1
if i == len(data)-1 and prev != i:
res.append(data[prev:])
return res
get_zero_sliced(data)