📅  最后修改于: 2022-03-11 14:47:18.157000             🧑  作者: Mango
# Split a Python List into Chunks using itertools
from itertools import zip_longest
sample_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
chunk_size=2
result=list(zip_longest(*[iter(sample_list)]*chunk_size, fillvalue=''))
print(result)
chunked_list = [list(item) for item in list(zip_longest(*[iter(sample_list)]*chunk_size, fillvalue=''))]
print(chunked_list)