mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-03-04 14:48:45 +00:00
Update graph remove_neighbor error handling (#93)
This commit is contained in:
@@ -30,14 +30,11 @@ class Node:
|
||||
self.adj_nodes[neighbor.key] = neighbor
|
||||
|
||||
def remove_neighbor(self, neighbor):
|
||||
if neighbor is None:
|
||||
raise Exception('Invalid neighbor')
|
||||
if neighbor.key in self.adj_nodes:
|
||||
neighbor.incoming_edges -= 1
|
||||
del self.adj_weights[neighbor.key]
|
||||
del self.adj_nodes[neighbor.key]
|
||||
else:
|
||||
if neighbor is None or neighbor.key not in self.adj_nodes:
|
||||
raise Exception('Invalid neighbor')
|
||||
neighbor.incoming_edges -= 1
|
||||
del self.adj_weights[neighbor.key]
|
||||
del self.adj_nodes[neighbor.key]
|
||||
|
||||
|
||||
class Graph:
|
||||
|
||||
Reference in New Issue
Block a user