SymPy | Permutation.next_nonlex() in Python
Last Updated :
27 Aug, 2019
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
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import 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
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import 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
Share your thoughts in the comments
Please Login to comment...