changeset 4:9d0cf96b6a3b

Updates to Graph.py after looking at Prof. Downey's code.
author Brian Neal <bgneal@gmail.com>
date Thu, 29 Nov 2012 20:37:03 -0600
parents e3d0a85354b3
children 8e44660965ef
files Graph.py
diffstat 1 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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)