Python中的SymPy Partition.prev_lex()
Partition.prev_lex() : prev_lex()是一个Sympy Python库函数,用于返回前一个整数分区,n的列序。如果分区是[1,…,1],这个排序就会环绕[n]。
语法 : sympy.combinatorics.partitions.Partition.prev_lex()
返回:之前的整数分区,n为lexicographical顺序。
代码#1:prev_lex()示例
# Python code explaining
# SymPy.prev_lex()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition
# Using from sympy.combinatorics.partitions.Partition.prev_lex() method
p = IntegerPartition([312, 121, 14, 5])
print('p : ', p)
print('\nPrevious Integer : ', p.prev_lex())
输出 :
p : [312, 121, 14, 5]
Previous Integer : [312, 121, 14, 4, 1]
代码#2:prev_lex()示例
# Python code explaining
# SymPy.prev_lex()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition
# Using from sympy.combinatorics.partitions.Partition.prev_lex() method
p = IntegerPartition([1, 312, 121, 14,
34, 56, 32])
print('p : ', p)
print('\nPrevious Integer : ', p.prev_lex())
输出 :
p : [312, 121, 56, 34, 32, 14, 1]
Previous Integer : [312, 121, 56, 34, 32, 13, 2]