我正在试验用于组合的渐近api。
首先,组合不需要替换.
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但是,组合()方法似乎不支持'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发布于 2019-01-10 12:01:05
这是另一种方法。
Init签名: sympy.utilities.iterables.combinations_with_replacement(self,/,*args,**kwargs) Docstring: combinations_with_replacement (迭代,r) ->combinations_with_replacement对象 返回迭代中元素的连续r长度组合,允许单个元素具有连续重复。combinations_with_replacement('ABC',2) --> AA AB AC BB BC CC类型:类型
https://stackoverflow.com/questions/54128074
复制相似问题