SymPy | Subset.next_gray () in Python

Python Methods and Functions

Subset.next_gray (): next_gray () — nice Python library function that returns the next ordered subset of Gray code.

Syntax:
sympy.combinatorics.subset.Subset.next_gray ()

Return:
the next Gray code ordered subset

Code # 1: next_gray () example

# Python code explaining
# SymPy.Subset.next_gray ()

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.subsets import Subset

  
# Used from
# sympy.combinatorics.subset.Subsets .next_gray ()

 
# Create a subset

a = Subset ([ ` c` , `d` ], [ `geek` , ` for` , `c` , ` d` ])

 
# next_gray value

print ( "Subset a next_gray : " , an ext_gray (). subset)

Output:

Subset a next_gray: [`c`]

Code # 2: next_gray () example

# Python code explaining
# SymPy.Subset.next_gray ()

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.subsets import Subset

 
# Use from
# symp y.combinatorics.subset.Subsets.next_gray ()

 
# Create a subset

a = Subset ([ `k` , ` d` ], [ ` 23` , `k` , `d` ])

 
# next_gray value

print ( "Subset a next_gray:" , a.next_gray (). subset)

Output:

Subset a next_gray: [`k`]





Get Solution for free from DataCamp guru