Learn

Trees are an abstract idea that we’re making concrete in Python. When implementing these abstract data structures, it’s important to leverage the features of your language.

Let’s refactor .remove_child() to use Python’s list comprehension. As a quick refresher on list comprehension:

nums = [1, 2, 3, 4, 5] evens = [num for num in nums if num % 2 == 0] # [2, 4]

Instructions

1.

Replace the existing code in .remove_child and assign self.children to a list comprehension which performs the same logic.

Sign up to start coding

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?