Last active
September 3, 2019 21:42
-
-
Save alexgolec/1ba52c463a4f40483852c64260d32561 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 RateGraph(object): | |
def __init__(self, rates): | |
'Initialize the graph from an iterable of (start, end, rate) tuples.' | |
self.graph = {} | |
for orig, dest, rate in rates: | |
self.add_conversion(orig, dest, rate) | |
def add_conversion(self, orig, dest, rate): | |
'Insert a conversion into the graph.' | |
if orig not in self.graph: | |
self.graph[orig] = {} | |
self.graph[orig][dest] = rate | |
def get_neighbors(self, node): | |
'Returns an iterable of the nodes neighboring the given node.' | |
if node not in self.graph: | |
return None | |
return self.graph[node].items() | |
def get_nodes(self): | |
'Returns an iterable of all the nodes in the graph.' | |
return self.graph.keys() |
whoooooooops, thanks for pointing that out
fixed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The comment in line 10 contains spoilers ;)