Python中的SymPy Partition.next_lex()
Partition.next_lex() : next_lex()是一个sympy Python库函数,它返回下一个整数分区,n为lexicographical顺序。如果分区是[1,…,1],这个排序就会环绕[n]。
**语法 : ** sympy.combinatorics.partitions.Partition.next_lex()
返回 :下一个整数分区,n为lexicographical顺序
代码 #1 : next_lex() 示例
Python3 1=1
# Python code explaining
# SymPy.next_lex()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition
# Using from sympy.combinatorics.partitions.Partition.next_lex() method
p = IntegerPartition([312, 121, 14, 5])
print('p : ', p)
print('\nNext Integer : ', p.next_lex())
输出 :
p : [312, 121, 14, 5] Next Integer : [312, 121, 15, 1, 1, 1, 1]
代码#2:next_lex()示例
Python3 1=1
# Python code explaining
# SymPy.next_lex()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition
# Using from sympy.combinatorics.partitions.Partition.next_lex() method
p = IntegerPartition([1, 312, 121, 14,
34, 56, 32])
print('p : ', p)
print('\nNext Integer : ', p.next_lex())
输出 :
p : [312, 121, 56, 34, 32, 14, 1] Next Integer : [312, 121, 56, 34, 32, 15]