-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Organising information: trees", exercise 2 #32
Labels
Comments
from anytree import Node
from tree_instructions import *
def test_breadth_first_visit_it(root_node, expected):
return breadth_first_visit_it(root_node) == expected
def breadth_first_visit_it(root_node):
tree_list = []
tree_list.append(root_node)
while len(root_node.children) > 0:
for child in root_node.children:
tree_list.append(child)
for grandchild in child.children:
grandchild.parent = root_node
child.parent = None
return tree_list
test_list = [book, chapter_1, chapter_2, text_8, paragraph_1, paragraph_2, paragraph_3, text_7, text_1, quotation_1, text_3, quotation_2, text_5, text_6, text_2, text_4]
print(test_breadth_first_visit_it(book, test_list)) |
Functions:
Trees:
|
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write the pure iterative version of the function defined in the previous exercise in Python.
The text was updated successfully, but these errors were encountered: