如果没有,我会使用与您相同的想法
pairwise:
from itertools import combinationsdef partitions(items, k): def split(indices): i=0 for j in indices: yield items[i:j] i = j yield items[i:] for indices in combinations(range(1, len(items)), k-1): yield list(split(indices))



