SymPy | Python中的 Subset.prev_lexicographic()
Subset.prev_lexicographic() :prev_lexicographic()是一个 sympy Python库函数,它返回前一个按字典顺序排列的子集。
Syntax :
sympy.combinatorics.subset.Subset.prev_lexicographic()
Return :
the previous Gray code ordered subset.
代码 #1:prev_lexicographic() 示例
# Python code explaining
# SymPy.Subset.prev_lexicographic()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
# Using from
# sympy.combinatorics.subset.Subsets.prev_lexicographic()
# Creating Subset
a = Subset(['c', 'd'], ['geek', 'for', 'c', 'd'])
# prev_lexicographic value
print ("Subset a prev_lexicographic : ", a.prev_lexicographic().subset)
输出 :
Subset a prev_lexicographic : [‘c’]
代码 #2:prev_lexicographic() 示例
# Python code explaining
# SymPy.Subset.prev_lexicographic()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
# Using from
# sympy.combinatorics.subset.Subsets.prev_lexicographic()
# Creating Subset
a = Subset([2, 3, 4], [1, 2, 3, 4, 5])
# prev_lexicographic value
print ("Subset a prev_lexicographic : ", a.prev_lexicographic().subset)
输出 :
Subset a prev_lexicographic : [2, 3]