Open In App

SymPy | Permutation.next_nonlex() in Python

Last Updated : 27 Aug, 2019
Comments
Improve
Suggest changes
Like Article
Like
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 Python3 1=1
# 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 Python3 1=1
# 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)

Next Article
Article Tags :
Practice Tags :

Similar Reads