Skip to Content
Learn
Trees: Python
Tree Review

Congratulations, you have implemented a tree in Python.

For review, in our implementation:

  • Trees are a Python class called TreeNode.
  • A TreeNode has two properties, value and children.
  • Nodes hold any type of data inside value.
  • children is a list, which can be empty or hold other instances of TreeNode.
  • We add to children by using the list method .append.
  • We remove from children by filtering the list.

Instructions

This implementation will come in handy for a variety of algorithms in the future. Excellent work and happy planting!

Folder Icon

Sign up to start coding

Already have an account?