SymPy | Partition.as_dict() in Python

Partition.as_dict() : as_dict() is a sympy Python library function that returns the partition as a dictionary. In this dictionary, the keys are the partition integers. The values are the multiplicity of that integer.

Syntax : sympy.combinatorics.partitions.Partition.as_dict()

Return : Partition as a dictionary



Code #1 : as_dict() Example

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code explaining
# SymPy.as_dict()
  
# importing SymPy libraries
  
from sympy.utilities.iterables import default_sort_key
from sympy.combinatorics.partitions import Partition
from sympy.abc import x, y
from sympy.combinatorics.partitions import IntegerPartition
  
# Using from sympy.combinatorics.partitions.Partition.as_dict() method 
IntegerPartition([11]*3 + [342] + [13]*4).as_dict()

chevron_right


Output :

{11: 3, 13: 4, 342: 1}

Code #2 : as_dict() Example

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code explaining
# SymPy.as_dict()
  
# importing SymPy libraries
  
from sympy.utilities.iterables import default_sort_key
from sympy.combinatorics.partitions import Partition
from sympy.abc import x, y
from sympy.combinatorics.partitions import IntegerPartition
  
# Using from sympy.combinatorics.partitions.Partition.as_dict() method 
IntegerPartition([100]*100 + [342]*10 + [13] + [2232]).as_dict()

chevron_right


Output :

{13: 1, 100: 100, 342: 10, 2232: 1}



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.