Python | SymPy Permutation.cardinality () method

Python Methods and Functions

Permutation.cardinality (): cardinality () — nice Python library function that returns every possible number of permutations.

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

Return: all the possible number of permutation

Code # 1: cardinality example ()

Output:

Permutation a - cardinality form: 24
Permutation b - cardinality form: 720

Code # 2: cardinality () example — 2D permutation

# Python code explaining
# SymPy.Permutation.cardinality ()

 
# import SymPy libraries

from sympy.combinatorics.partitions import Partition

from sympy.combinatorics.permutations import Permutation

 
# Using the sympy.combinatorics.permutations.Permutation.cardinality () method

 
# create permutation

a = Permutation ([[ 2 , 0 ], [ 3 , 1 ]])

 

b = Permutation ([ 1 , 3 , 5 , 4 , 2 , 0 ])

 

 

print ( "Permutation a - cardinality form:" , a.cardinality)

print ( " Permutation b - cardinality form: " , b.cardinality)

# Python code explaining
# SymPy.Permutation.cardinality ()

 
# import SymPy libraries

from sympy.combinatorics.partitions import Partition

from sympy.combinatorics.permutations import Permutation

 
# Using the sympy.combinatorics.permutations.Permutation.cardinality () method

 
# create permutation

a = Permutation ([[ 2 , 4 , 0 ], 

[ 3 , 1 , 2 ],

[ 1 , 5 , 6 ]])

 

 

print ( "Permutation a - cardinality form:" , a.cardinality)

Exit :

Permutation a - cardinality form: 5040





Get Solution for free from DataCamp guru