Friday, October 17, 2025
HomeLanguagesSymPy | Partition.prev_lex() in Python

SymPy | Partition.prev_lex() in Python

Partition.prev_lex() : prev_lex() is a sympy Python library function that returns the previous integer partition, n in lexicographical order. This ordering wraps around [n] if the partition is [1, …, 1].
 

Syntax : sympy.combinatorics.partitions.Partition.prev_lex()
Return : previous integer partition, n in lexicographical order 
 

Code #1 : prev_lex() Example 
 

Python3




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


Output : 
 

p : [312, 121, 14, 5]
Previous Integer : [312, 121, 14, 4, 1] 
 

Code #2 : prev_lex() Example 
 

Python3




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


Output : 
 

p : [312, 121, 56, 34, 32, 14, 1]
Previous Integer : [312, 121, 56, 34, 32, 13, 2] 
 

 

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

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS