Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Generating a LabelledBinaryTree from its string representation

Consider

t = Permutation([1, 3, 2]).increasing_tree() 
print t
print t.parent()

This gives

1[., 2[3[., .], .]] 
Labelled binary trees

Conversely, I would like to generate a labelled binary tree from its string representation.

s = "1[., 2[3[., .], .]]" 
LabelledBinaryTree(s)

This gives

ValueError: malformed string

How do I have to proceed?

Generating a LabelledBinaryTree from its string representation

Consider

t = Permutation([1, 3, 2]).increasing_tree() 
print t
print t.parent()

This gives

1[., 2[3[., .], .]] 
Labelled binary trees

Conversely, I would like to generate a labelled binary tree from its string representation.

s = "1[., 2[3[., .], .]]" 
LabelledBinaryTree(s)

This gives

ValueError: malformed string

How do I have to proceed?

EDIT: I will turn now my question into a feature request:

Make all trees reconstructable by their string representation!

This would be a great help for developing and testing one's code. Below Maybeso83 demonstrates how this can be done for labelled binary trees.