# SymPy | Permutation.inversions() in Python

Permutation.inversions() : inversions() is a sympy Python library function that returns the number of inversions value of the permutation in the argument.
The inversion vector includes those elements whose value indicates the no. of elements in the permutation that are < it and lie on its right-hand side.

Syntax : Return : number of inversions value of the permutation in argument

Code #1 : inversions() Example

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

Output :

Permutation a – inversions form : 4
Permutation b – inversions form : 9

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

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

Output :

Permutation a – inversions form : 10

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.