n项的组合数

互联网 更新时间:2023-04-26 21:02:37

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))

更多推荐

组合

本文发布于:2023-04-26 21:02:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/hyzx/aabbda123b69958d4101a25efe6a3126.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 89740文章数
  • 23108阅读数
  • 0评论数