Open In App

SymPy | Permutation.next_nonlex() in Python

Last Updated : 27 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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

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

Return : next permutation in non lexicographical order

Code #1 : next_nonlex() Example




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


Output :

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

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




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


Output :

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads