SymPy | Subset.prev_gray () in Python

Python Methods and Functions

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

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

Return:
the previous Gray code ordered subset.

Code # 1: prev_gray () example

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

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.subsets import Subset

< code class = "undefined spaces">  
# Used from
# sympy.combinatorics.subset. Subsets.prev_gray ()

 
# Create a subset

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

 
# prev_gray value

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

Output:

Subset a prev_gray: ['d']

Code # 2: prev_gray () example

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

 
# import SymPy libraries

from sympy.combinatorics import Permutation , Cycle

from sympy.combinatorics.subsets import Subset

 
# Using from
 # sympy.combinatorics.subset.Subsets.prev_gray ()

 
# Create subsets

a = Subset ([ 2 , 3 , 4 ], [ 1 , 2 , 3 , 4 , 5 ])

 
# prev_gray value

print ( "Subset a prev_gray:" , a.prev_gray (). subset) < / p>

Output:

Subset a prev_gray: [2, 3, 4, 5]





Get Solution for free from DataCamp guru