Я наткнулся на это решение на net:
Источник: http://cbio.ufs.ac.za/live_docs/nbn_tut/trees.html
Код: Выделить всё
class node(object):
def __init__(self, value, children = []):
self.value = value
self.children = children
def __repr__(self, level=0):
ret = "\t"*level+repr(self.value)+"\n"
for child in self.children:
ret += child.__repr__(level+1)
return ret
< /code>
Этот код печатает дерево следующим образом: < /p>
'grandmother'
'daughter'
'granddaughter'
'grandson'
'son'
'granddaughter'
'grandson'
Подробнее здесь: https://stackoverflow.com/questions/202 ... -in-python