Skip to content

Instantly share code, notes, and snippets.

@zshihang
Created March 8, 2016 03:52
Show Gist options
  • Save zshihang/9d93de0bcd98547d9d85 to your computer and use it in GitHub Desktop.
Save zshihang/9d93de0bcd98547d9d85 to your computer and use it in GitHub Desktop.
Simple implementation of graph
class SimpleGraph(object):
def __init__(self, edges, weights=None):
self._edges = edges
self._weights = weights
def neighbors(self, id):
return self._edges[id]
def cost(self, start, end):
return self._weights[(start, end)]
@property
def nodes(self):
return self._edges.keys()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment