sympy.utilities.iterables公司.combinations()是否替换?

2024-10-08 18:26:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在试验sympyapi的组合。你知道吗

首先,没有替换的组合。。。你知道吗

from sympy.functions.combinatorial.numbers import nC
from sympy.utilities.iterables import combinations

nC('abc', 2)
# >>> 3

list(combinations('abc', 2))
# >>> [('a', 'b'), ('a', 'c'), ('b', 'c')]

我现在想列出组合替换

nC('abc', 2, replacement=True)
# >>> 6

但是,combinations()方法似乎不支持“replacements”参数?你知道吗

Init signature: combinations(self, /, *args, **kwargs)
Docstring:     
combinations(iterable, r) --> combinations object

Return successive r-length combinations of elements in the iterable.

combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)
Type:           type

Tags: fromimportiterablefunctionslistabcutilitiessympy
1条回答
网友
1楼 · 发布于 2024-10-08 18:26:20

这是另一种方法

Init signature: sympy.utilities.iterables.combinations_with_replacement(self, /, *args, **kwargs) Docstring:
combinations_with_replacement(iterable, r) > combinations_with_replacement object

Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats. combinations_with_replacement('ABC', 2) > AA AB AC BB BC CC Type: type

相关问题 更多 >

    热门问题