Wednesday, October 1, 2025
HomeLanguagesSymPy | Permutation.next_lex() in Python

SymPy | Permutation.next_lex() in Python

Permutation.next_lex() : next_lex() is a sympy Python library function that returns the next permutation in lexicographical order and if in case the self is the last permutation in lexicographical order it returns None.

Syntax : sympy.combinatorics.permutations.Permutation.next_lex()

Return : next permutation in lexicographical order

Code #1 : next_lex() Example




# Python code explaining
# SymPy.Permutation.next_lex()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from sympy.combinatorics.permutations.Permutation.next_lex() method 
  
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
  
b = Permutation([1, 3, 5, 4, 2, 0])
  
  
print ("Permutation a - next_lex form : ", a.next_lex())
print ("Permutation b - next_lex form : ", b.next_lex())


Output :

Permutation a – next_lex form : (0 2 1 3)
Permutation b – next_lex form : (5)(0 1 4 3 2)

Code #2 : next_lex() Example – 2D Permutation




# Python code explaining
# SymPy.Permutation.next_lex()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from sympy.combinatorics.permutations.Permutation.next_lex() method 
  
# creating Permutation
a = Permutation([[2, 4, 0], 
                 [3, 1, 2],
                 [1, 5, 6]])
  
  
print ("Permutation a - next_lex form : ", a.next_lex())


Output :

Permutation a – next_lex form : (6)(0 3 5)(1 2 4)

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

Most Popular

Dominic
32330 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11926 POSTS0 COMMENTS
Shaida Kate Naidoo
6815 POSTS0 COMMENTS
Ted Musemwa
7078 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6774 POSTS0 COMMENTS