I've tried searching for a solution to this, but my ignorance of precise terminology doesn't help, hopefully the title of the question and the code below is enough explanation.
Here's my working so far:
C = [1,1,1,1,2,3,1,1,1,2,1]
sub_C = []
chunked_C = []
counter = 0
for i in C:
counter += i
if counter <= 3:
sub_C.append(i)
else:
chunked_C.append(list(sub_C))
del sub_C[:]
counter = i
sub_C.append(i)
print chunked_C
I want chunked_C to produce: [[1,1,1],[1,2],[3],[1,1,1],[2,1]]
Not sure where I'm going wrong, perhaps someone can help.
Edit: I've corrected the typos.
Also:
A slight revision in that I would need the incomplete tail of the list to be chunked too i.e. where the value is less than 3 but I run out of numbers.
e.g:
C = [1,1,1,1,2,3,1,1,1,2,1,1]
so chunked_C = [[1,1,1],[1,2],[3],[1,1,1],[2,1],[1]]
Hope that makes sense.
A further revision:
if C = [1,1,1,1,1,2,3,1,1,1,2,1]
chunked_C would equal [[1,1,1],[1,1],[2],[3],[1,1,1],[2,1]]
So I guess the logic needs to be revised further.