Thursday, June 18, 2026
HomeLanguagesSymPy | Partition.next_lex() in Python

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




# 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]

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS