Python | Simpius IntegerPartition () method

Learn examples from DataCamp guru:

Using the sympy.combinatorics.IntegerPartition().as_dict() method we can get a dictionary of integer elements from subarrays along with the values ​​of its coefficients using sympy .combinatorics.IntegerPartition (). as_dict () .

Syntax: sympy.combinatorics.IntegerPartition (). as_dict ()
Return: Return the dictionary having elements along with it`s coefficient values.

Example # 1:
In this example, we can see that using sympy.combinatorics.IntegerPartition (). As_dict () we can get a dictionary of integer values ​​with its coefficient values.

# import sympy and IntegerPartition

from sympy.combinatorics.partitions import IntegerPartition

from sympy import *

 
# Using sympy.combinatorics.partitions.IntegerPartition (). As_dict () method

gfg = IntegerPartition ([ 1 ] + 3 * [ 2 , 3 ]). as_dict ()

 

print (gfg)

Output:

{ 3: 3, 2: 3, 1: 1}

Example # 2:

# import sympy and IntegerPartition

from sympy.combinatorics.partitions import IntegerPartition

from sympy import *

  
# Using sympy.combinatorics.partitions.IntegerPartition (). As_dict () method

gfg = IntegerPartition ([ 1 ] + 2 * [ 2 , 3 ] + 4 * [ 4 ] + 5 * [ 5 ]). as_dict ()

 

print (gfg)

Output:

{5: 5, 4: 4, 3: 2, 2: 2, 1: 1}

Learn examples from DataCamp guru: