1.源码实现
import itertools
def nchoosek(a, b, d=1, n=1):
c = []
for i in itertools.combinations(range(a,b+1,d),n):
c.append(list(i))
return c
a = nchoosek(2, 10, d=2, n=4)
print(a)
2.运行及结果
$ python3 example.py
[[2, 4, 6, 8], [2, 4, 6, 10], [2, 4, 8, 10], [2, 6, 8, 10], [4, 6, 8, 10]]
网友评论