SymPy | Prufer.prufer_repr () in Python

Python Methods and Functions

Prufer.prufer_repr (): prufer_repr () — nice Python library function that returns a Prufer sequence for a Prufer object. By deleting the highest numbered vertex, then writing down the node to which it was attached, and finally continuing until only two vertices remain, the sequence can be found.

Syntax:
sympy.combinatorics.Prufer.prufer.prufer_repr ()

Return:
Prufer sequence for the Prufer object

Code # 1: Example prufer_repr ()

# Python code explaining
# SymPy.Prufer.prufer_repr ()

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.prufer import Prufer

 
# Using from
# sympy.combinatorics.prufer.Prufer.prufer_repr ()

 
# Create Prufer

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

 
# prufer_repr value

print ( " Prufer a prufer_repr: " , a.prufer_repr)

Output:

Prufer a prufer_repr: [1, 2, 3]

Code # 2: Example prufer_repr ()

# Python code explaining
# SymPy.Prufer.prufer_repr ()

 
# import SymPy libraries

from sympy.combinatorics import Permutation, Cycle

from sympy.combinatorics.prufer import Prufer

  
# Use from
# sympy.combinatorics.prufer.Prufer.prufer_repr ()

  
# Create Prufer

b = Prufer ([ 1 , 2 , 3 , 2 , 4 , 5 ], [ 6 , 7 ], [ 8 ])

 
# prufer_repr value

print ( " Prufer b prufer_repr: " , b.prufer_repr)

Output:

Prufer b prufer_repr: [1, 2, 3, 2, 4, 5]





Get Solution for free from DataCamp guru