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)