Python n项组合数

Python n项组合数,python,algorithm,math,combinations,discrete-mathematics,Python,Algorithm,Math,Combinations,Discrete Mathematics,有没有代数公式告诉我ntemr的不同组合 如果我有: {0: ['Hello!']} {1: ['Welcome']} {2: ['to']} 所有组合将是: ['Hello!', 'Welcome', 'to'], ['Hello!', 'to', 'Welcome'], ['Welcome', 'Hello!', 'to'], ['Welcome', 'to', 'Hello!'], ['to', 'Hello!', 'Welcome'], ['t

有没有代数公式告诉我
n
temr的不同组合

如果我有:

{0: ['Hello!']}

{1: ['Welcome']}

{2: ['to']}
所有组合将是:

['Hello!',  'Welcome', 'to'],
['Hello!',  'to',      'Welcome'],
['Welcome', 'Hello!',  'to'],
['Welcome', 'to',      'Hello!'],
['to',      'Hello!',  'Welcome'],
['to',      'Welcome', 'Hello!'],
但描述这一点的公式是什么?然后,我会使用这个公式来编写我的程序,并根据我现有的单词创建所有可能的三元组。我已经看过这个链接,但还没有找到答案:


您描述的是n个对象的排列数量。有n!=1 × 2 × ... ×n(也称为n阶乘)这样的排列。

您描述的是n个对象的排列数。有n!=1 × 2 × ... ×n(也称为n阶乘)这样的置换。

您需要
n
项的置换,
itertools
具有置换方法。您可以按如下方式使用它:

导入itertools
lst=['A','B','C','D']
z=itertools.置换(lst,len(lst))
打印(列表(z))
如果您想了解更多信息:

导入itertools
def置换(iterable,r=None):
pool=元组(iterable)
n=长(池)
如果r不是其他r,则r=n
对于itertools.product中的索引(范围(n),重复=r):
如果len(设置(索引))==r:
收益元组(索引中i的池[i]
lst=['A','B','C','D']
z=排列(lst,len(last))
打印(列表(z))

您需要
n
术语的排列,
itertools
具有排列方法。您可以按如下方式使用它:

导入itertools
lst=['A','B','C','D']
z=itertools.置换(lst,len(lst))
打印(列表(z))
如果您想了解更多信息:

导入itertools
def置换(iterable,r=None):
pool=元组(iterable)
n=长(池)
如果r不是其他r,则r=n
对于itertools.product中的索引(范围(n),重复=r):
如果len(设置(索引))==r:
收益元组(索引中i的池[i]
lst=['A','B','C','D']
z=排列(lst,len(last))
打印(列表(z))

您能举例说明并非所有列表都是一个元素吗?应为3x2x1。对于第一个插槽,您有3个选择,第二个插槽有2个,第三个插槽只有1个。但是我认为您的第五行和第六行应该从
,如果我没有听错的话?是的,对不起,我正在修复。您能举一个例子说明并非所有列表都是一个元素吗?应该是3x2x1。对于第一个插槽,您有3个选择,第二个插槽有2个选择,第三个插槽只有1个选择。但是我认为您的第五行和第六行应该从
,如果我没有听错的话?是的,对不起,我正在修复它