【发布时间】:2021-02-23 14:33:50
【问题描述】:
在给定的值列表中,我想获得给定长度的所有组合,例如:
given_list = [a,b]
given_lenght_of_combinations = 3
预期输出:
a,a,a
a,a,b
a,b,a
a,b,b
b,a,a
.
.
.
b,b,b
b,b,a
b,a,b
b,a,a
.
.
.
我尝试过使用 itertools 中的排列和组合,但无法正常工作。
谁能帮忙?
【问题讨论】:
标签: python-3.x combinations permutation itertools