Tree Traversal¶
🎯 Output all nodes in a tree.
Collect all living beings from the following tree structure in a single list.
tree3 = [
['Rose', 'banana tree'],
[
[
['hammerhead shark', 'stingray'],
[
['chimp', 'human'],
'rat'
]
],
['bee', 'ant']
]
]
Hint
Hints:
Draw the tree. In which order would you go through the beings?
How can you check whether you are dealing with a string or a list?
Is it basically possible to walk trees of any depth with the same program?
Research “Tree Traversal”
Translated withwww.DeepL.com