将列表分成指定大小 可迭代对象 在指定位置分割可迭代对象

from more_itertools import chunked

my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

chunks = list(chunked(my_list, 3))
print(chunks)
# 输出:[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]

from more_itertools import split_at

my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

splits = list(split_at(my_list, 4))
print(splits)
# 输出:[[1, 2, 3, 4], [5, 6, 7, 8, 9, 10]]

你可能感兴趣的:(python,笔记,python)