Related Articles

# Python | SymPy Permutation.cycle_structure() method

• Last Updated : 27 Aug, 2019

Permutation.cycle_structure() : cycle_structure() is a sympy Python library function that returns the cycle structure of the permutation as a dictionary and this will indicate the multiplicity of each cycle length.

Syntax :
sympy.combinatorics.permutations.Permutation.cycle_structure()

Return :
cycle structure of the permutation as a dictionary

Code #1 : cycle_structure() Example

 `# Python code explaining``# SymPy.Permutation.cycle_structure()`` ` `# importing SymPy libraries``from` `sympy.combinatorics.partitions ``import` `Partition``from` `sympy.combinatorics.permutations ``import` `Permutation`` ` `# Using from ``# sympy.combinatorics.permutations.Permutation.cycle_structure() method `` ` `# creating Permutation``a ``=` `Permutation([``2``, ``0``, ``3``, ``1``, ``5``, ``4``])`` ` `b ``=` `Permutation([``3``, ``1``, ``2``, ``5``, ``4``, ``0``])`` ` ` ` `print` `(``"Permutation a - cycle_structure form : "``, a.cycle_structure)``print` `(``"Permutation b - cycle_structure form : "``, b.cycle_structure)`

Output :

Permutation a – cycle_structure form : {2: 1, 4: 1}
Permutation b – cycle_structure form : {1: 3, 3: 1}

Code #2 : cycle_structure() Example – 2D Permutation

 `# Python code explaining``# SymPy.Permutation.cycle_structure()`` ` `# importing SymPy libraries``from` `sympy.combinatorics.partitions ``import` `Partition``from` `sympy.combinatorics.permutations ``import` `Permutation`` ` `# Using from ``# sympy.combinatorics.permutations.Permutation.cycle_structure() method `` ` `# creating Permutation``a ``=` `Permutation([[``2``, ``4``, ``0``], ``                 ``[``3``, ``1``, ``2``],``                 ``[``1``, ``5``, ``6``]])`` ` `# SELF COMMUTATING    ``print` `(``"Permutation a - cycle_structure form : "``, a.cycle_structure)`

Output :

Permutation a – cycle_structure form : {7: 1}

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up