SymPy | Python中的 Subset.next_gray()
Subset.next_gray() :next_gray()是一个 sympy Python库函数,它返回下一个格雷码有序子集。
Syntax :
sympy.combinatorics.subset.Subset.next_gray()
Return :
the next Gray code ordered subset
代码 #1:next_gray() 示例
# Python code explaining
# SymPy.Subset.next_gray()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
# Using from
# sympy.combinatorics.subset.Subsets.next_gray()
# Creating Subset
a = Subset(['c', 'd'], ['geek', 'for', 'c', 'd'])
# next_gray value
print ("Subset a next_gray : ", a.next_gray().subset)
输出 :
Subset a next_gray : [‘c’]
代码 #2:next_gray() 示例
# Python code explaining
# SymPy.Subset.next_gray()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
# Using from
# sympy.combinatorics.subset.Subsets.next_gray()
# Creating Subset
a = Subset(['k', 'd'], ['23', 'k', 'd'])
# next_gray value
print ("Subset a next_gray : ", a.next_gray().subset)
输出 :
Subset a next_gray : [‘k’]