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
def split_on_zero(data): start = 0 for (i, n) in enumerate(data): if n == 0: yield data[start:i] start = i + 1 yield data[start:] >>> list(split_on_zero([3, 7, 4, 0, 1, 3, 7])) [[3, 7, 4], [1, 3, 7]] >>> list(split_on_zero([0, 1, 2, 0, 3, 4, 5, 0])) [[], [1, 2], [3, 4, 5], []]