-
-
Save joelburton/439d801faed4f8a69c6f to your computer and use it in GitHub Desktop.
A neat idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, data, children=None): | |
self.data = data | |
self.children = children or [] | |
def find(self, data): | |
for i in self.descendants(): | |
if i.data == data: | |
return i | |
def descendants(self): | |
yield self | |
for i in self.children: | |
yield from i.descendants() | |
def __repr__(self): | |
return "Node({!r})".format(self.data) | |
def __iter__(self): | |
yield from self.children | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment