python batch list code example
Example 1: split list into lists of equal length python
[lst[i:i + n] for i in range(0, len(lst), n)]
Example 2: batch a list python
l = [1,2,3,4,5,6,7,8,9,10]
batch_size = 3
for i in range(0, len(l), batch_size):
print(l[i:i+batch_size])
# i skip 3 (batch) on each itteration
# l[0: 0+batch]
# l[batch: batch+batch] ...
>>> [1,2,3]
>>> [4,5,6]
>>> [7,8,9]
>>> [10]