SymPy | Partition.next_lex() in Python
Partition.next_lex() : next_lex() is a sympy Python library function that returns the next integer partition, n in lexicographical order. This ordering wraps around [n] if the partition is [1, …, 1].
Syntax : sympy.combinatorics.partitions.Partition.next_lex() Return : next integer partition, n in lexicographical order
Code #1 : next_lex() Example
Python3
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition
p = IntegerPartition([ 312 , 121 , 14 , 5 ])
print ( 'p : ' , p)
print ( '\nNext Integer : ' , p.next_lex())
|
Output :
p : [312, 121, 14, 5] Next Integer : [312, 121, 15, 1, 1, 1, 1]
Code #2 : next_lex() Example
Python3
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition
p = IntegerPartition([ 1 , 312 , 121 , 14 ,
34 , 56 , 32 ])
print ( 'p : ' , p)
print ( '\nNext Integer : ' , p.next_lex())
|
Output :
p : [312, 121, 56, 34, 32, 14, 1] Next Integer : [312, 121, 56, 34, 32, 15]
Last Updated :
12 Sep, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...