Making your data strucutre more friendly using the "in" keyword
A thought recently occurred to me: Wouldn’t it be convenient to have a Tree object Tree() that supports the “in” keyword in Python? This way, I could simply do tree = Tree.from_list([1,2,3,4,5]) ... if val in tree: ... The good news is, we can actually do that! To make the class Tree compatible with the “in” method, we need to implement the __iter__ method. This method should recursively yield its children, enabling us to traverse the entire tree....