Python中的SymPy Partition.as_dict()
Partition.as_dict() : as_dict() 是一个 sympy Python 库函数,它将分区作为一个字典返回。在这个字典中,键是分区的整数。值是该整数的倍数。
语法 : sympy.combinatorics.partitions.Partition.as_dict()
返回:作为一个字典的分区
代码 #1 : as_dict() 示例
# 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()
输出 :
{11: 3, 13: 4, 342: 1}
代码 #2 : as_dict() 示例
# 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()
输出 :
{13: 1, 100: 100, 342: 10, 2232: 1}