Answers for "python batch list"

8

split list into lists of equal length python

[lst[i:i + n] for i in range(0, len(lst), n)]
Posted by: Guest on March-31-2020
0

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]
Posted by: Guest on March-23-2021

Python Answers by Framework

Browse Popular Code Answers by Language