orl*_*rlp 5
您所描述的是n 个对象的排列数。有n个!= 1 × 2 × ... × n(也称为n factorial)这样的排列。
Ism*_*ana 5
您需要置换的n
条件,itertools
有排列方法。您可以按如下方式使用它:
import itertools
lst = ['A', 'B', 'C', 'D']
z = itertools.permutations(lst, len(lst))
print(list(z))
如果你想了解更多:https : //docs.python./3/library/itertools.html#itertools.permutations
import itertools
def permutations(iterable, r=None):
pool = tuple(iterable)
n = len(pool)
r = n if r is None else r
for indices in itertools.product(range(n), repeat=r):
if len(set(indices)) == r:
yield tuple(pool[i] for i in indices)
lst = ['A', 'B', 'C', 'D']
z = permutations(lst, len(last))
print(list(z))
更多推荐
组合
发布评论