p = [1,2,3,4,5,6,7,8,9]
[[1,2,3],
[4,5,6],
[7,8,9]]
def chunked(s, n):
current = 0
while True:
chunk = s[current : current+n]
current += n
if chunk:
yield chunk
else:
break
In [6]: list(chunked(p, 3))
Out[6]: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]