Learn

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!

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?