SymPy | Subset.prev_lexicographic () in Python

Python Methods and Functions

Subset.prev_lexicographic (): prev_lexicographic () — nice Python library function that returns the previous lexicographically ordered subset.

Syntax:
sympy.combinatorics.subset.Subset.prev_lexicographic ()

Return:
the previous Gray code ordered subset.

Code # 1: prev_lexicographic () example

# Python code explaining
# SymPy.Subset.prev_lexicographic ()

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.subsets import Subset

 
# Using from
# sympy.combinatorics.subset.Subsets.prev_lexicographic ()

 
# Create a subset

a = Subset ([ 'c' , 'd' ], [ ' geek' , 'for' , ' c' , ' d' ])

 
# prev_lexicographic value

print ( " Subset a prev_lexicographic: " , a.prev_lexicographic (). subset)

Output:

Subset a prev_lexicographic: ['c']

Code # 2: prev_lexicographic () example

# Python code explaining
# SymPy.Subset.prev_lexicographic ()

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.subsets import Subset

  
# Use from
# sympy.combinatorics.subset.Subsets.prev_lexicographic ()

 
# Create a subset

a = Subset ([ 2 , 3 , 4 ], [ 1 , 2 , 3 , 4 , 5 ])

 
# prev_lexicographic value

print ( "Subset a prev_lexicographic:" , a.prev_lexicographic (). subset)

Output:

Subset a prev_lexicographic: [2, 3]





Get Solution for free from DataCamp guru