Last active
May 6, 2017 19:34
-
-
Save codeboy101/19c9ced530c7c13197f98b64214bbd68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(object): | |
| def __init__(self, value, connected=None): | |
| self.value = value | |
| if connected: | |
| self.connected = [node for node in connected] | |
| else: | |
| self.connected = [] | |
| def add_connection(self, node): | |
| if isinstance(node, Node): | |
| self.connected.append(node) | |
| node.connected.append(self) | |
| else: | |
| raise Exception('nodes must be Node instances') | |
| def is_connected(self, node): | |
| return node in self.connected | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment