Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

SymPy | Subset.iterate_graycode() in Python

  • Last Updated : 26 Aug, 2019

Subset.iterate_graycode() : iterate_graycode() is a sympy Python library function that iterates over the k steps to get the respective Gray codes.

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

Return :
iterates over the k steps to get the respective Gray codes

Code #1 : iterate_graycode() Example




# Python code explaining
# SymPy.Subset.iterate_graycode()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
  
# Using from 
# sympy.combinatorics.subset.Subsets.iterate_graycode()
  
# Creating Subset
a = Subset(['c', 'd'], ['geek', 'for', 'c', 'd'])
  
# iterate_graycode value
print ("Subset a iterate_graycode : ", a.iterate_graycode(1).subset)

Output :

Subset a iterate_graycode : [‘c’]

Code #2 : iterate_graycode() Example




# Python code explaining
# SymPy.Subset.iterate_graycode()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
  
# Using from 
# sympy.combinatorics.subset.Subsets.iterate_graycode()
  
# Creating Subset
a = Subset(['c', 'd'], ['23', 'c', 'd'])
  
# iterate_graycode value
print ("Subset a iterate_graycode : ", a.iterate_graycode(3).subset)

Output :

Subset a iterate_graycode : [’23’, ‘c’, ‘d’]


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!