SymPy | Python中的 Subset.ksubsets()
Subset.ksubsets() :ksubsets()是一个 sympy Python库函数,它按字典顺序返回大小为 k 的子集。
Syntax :
sympy.combinatorics.subset.Subset.ksubsets()
Return :
the subsets of size k in lexicographic order.
代码 #1:ksubsets() 示例
# Python code explaining
# SymPy.Subset.ksubsets()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
# Using from
# sympy.combinatorics.subset.Subsets.ksubsets()
# Creating Subset
a = Subset.ksubsets(4, (['geek', 'for', 'c', 'd']))
# ksubsets value
print ("Subset a ksubsets : ", a.subset)
输出 :
Subset a ksubsets : [‘for’, ‘c’]
代码 #2:ksubsets() 示例
# Python code explaining
# SymPy.Subset.ksubsets()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
# Using from
# sympy.combinatorics.subset.Subsets.ksubsets()
# Creating Subset
a = Subset.ksubsets(4, ([2, 3, 4]))
# ksubsets value
print ("Subset a ksubsets : ", a.subset)
输出 :
Subset a ksubsets : [2, 3]