# HG changeset patch # User Brian Neal # Date 1354243023 21600 # Node ID 9d0cf96b6a3bdca96616178608ca410b99f582e0 # Parent e3d0a85354b3bb465508bd4ee2f796c6bcb7f992 Updates to Graph.py after looking at Prof. Downey's code. diff -r e3d0a85354b3 -r 9d0cf96b6a3b Graph.py --- a/Graph.py Thu Nov 29 20:19:27 2012 -0600 +++ b/Graph.py Thu Nov 29 20:37:03 2012 -0600 @@ -88,10 +88,9 @@ def remove_edge(self, e): """Removes the edge e from the graph.""" - for x in self.iterkeys(): - remove = [k for k, v in self[x].iteritems() if v is e] - for k in remove: - del self[x][k] + v, w = e + del self[v][w] + del self[w][v] def vertices(self): """Returns a list of the vertices in the graph.""" @@ -102,9 +101,8 @@ """"Returns a list of the edges in the graph.""" edge_set = set() - for x in self.iterkeys(): - for e in self[x].itervalues(): - edge_set.add(e) + for d in self.itervalues(): + edge_set.update(d.itervalues()) return list(edge_set)