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
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_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
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_lex form : " , a.next_lex())
|
Output :
Permutation a – next_lex form : (6)(0 3 5)(1 2 4)
Last Updated :
27 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...