Friday, January 16, 2026
HomeLanguagesSymPy | Partition.as_dict() in Python

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




# 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()


Output :

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

Code #2 : as_dict() Example




# 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()


Output :

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
117 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12062 POSTS0 COMMENTS
Shaida Kate Naidoo
6984 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS