SymPy | Subset.rank_gray () in Python

Python Methods and Functions

Subset.rank_gray (): rank_gray () — nice Python library function that returns the gray code ranking for a subset.

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

Return:
Gray code ranking of the subset

Code # 1: Example rank_gray ()

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

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.subsets import Subset

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

 
# Create a subset

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

 
# rank_gray value

print ( "Subset a rank_gray:" , a.rank_gray) 

Output:

Subset a rank_gray: 2

Code # 2: rank_gray () example

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

 
# importing SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.subsets import Subset

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

 
# Create a subset

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

  
# rank_gray value

print ( "Subset a rank_gray:" , a.rank_gray)

Output:

Subset a rank_gray: 11





Get Solution for free from DataCamp guru