Skip to content

Instantly share code, notes, and snippets.

@codeboy101
Last active May 6, 2017 19:34
Show Gist options
  • Select an option

  • Save codeboy101/19c9ced530c7c13197f98b64214bbd68 to your computer and use it in GitHub Desktop.

Select an option

Save codeboy101/19c9ced530c7c13197f98b64214bbd68 to your computer and use it in GitHub Desktop.
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