有没有一种简单的方法可以使用 Python 找到具有特定列表长度的所有子集?

Is there an easy way to find all the subset with a specific length of a list, using Python?

如果我有一个列表,说

a=[1,2,3,4]

我想指定一个长度,比如说3,那么我可以找到所有的子集:

[[1,2,3],
[1,2,4],
[2,3,4]]

Python 是否有功能可以让我快速完成此操作?

你可以这样做:

import itertools
print(list(itertools.combinations(your_set, length_of_subsets)))