📜  批处理列表 python 代码示例

📅  最后修改于: 2022-03-11 14:46:08.345000             🧑  作者: Mango

代码示例1
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]