📜  Python 使用 for 循环将列表拆分为块 - Python 代码示例

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

代码示例1
# Split a Python List into Chunks using For Loops

sample_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
chunked_list = list()
chunk_size = 2
for i in range(0, len(sample_list), chunk_size):
    chunked_list.append(sample_list[i:i+chunk_size])
print(chunked_list)