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
# 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()) |
Output :
p : [312, 121, 14, 5] Next Integer : [312, 121, 15, 1, 1, 1, 1]
Code #2 : next_lex() Example
Python3
# 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()) |
Output :
p : [312, 121, 56, 34, 32, 14, 1] Next Integer : [312, 121, 56, 34, 32, 15]