 # Python | SymPy Permutation.cycles () method

Permutation.cycles (): cycle () — a nice Python library function that returns the number of loops present in a permutation. This also includes a singleton.

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

Return:
number of cycles present in the permutation

Code # 1: cycle () Example

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

Output:

Permutation a – cycles form: 2
Permutation b – cycles form: 4

Code # 2: cycles () Example — 2D permutation

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

Logout:

Permutation a – cycles form: 1