Delete a single vertex and associated edges. >>> g = Graph() >>> g.add([1, 2], [1, 2, 3]) >>> del g[2] #will remove vertex 2 and edges [(1, 2), (2, 1), (2, 2), (2, 3)] >>> print g {1: {1, 3}, 3: {}} Raises LookupError if given non-existant vertex.
(self, head)
| 532 | dict.__setitem__(self, vid, self.VertexType(self, vid, value)) #XXX shallow copy |
| 533 | |
| 534 | def __delitem__(self, head): |
| 535 | """Delete a single vertex and associated edges. |
| 536 | >>> g = Graph() |
| 537 | >>> g.add([1, 2], [1, 2, 3]) |
| 538 | >>> del g[2] #will remove vertex 2 and edges [(1, 2), (2, 1), (2, 2), (2, 3)] |
| 539 | >>> print g |
| 540 | {1: {1, 3}, 3: {}} |
| 541 | |
| 542 | Raises LookupError if given non-existant vertex. |
| 543 | >>> del g[2] |
| 544 | Traceback (most recent call last): |
| 545 | ... |
| 546 | KeyError: 2 |
| 547 | """ |
| 548 | dict.__getitem__(self, head).clear() #removes out vertices (bypass key creation with dict.__getitem__) |
| 549 | for v in list(self[head].in_vertices()): #create copy (via list()) since in_vertices contents may change during iteration |
| 550 | del self[v][head] |
| 551 | super(Graph, self).__delitem__(head) |
| 552 | |
| 553 | def __str__(self): |
| 554 | """Return graph in adjacency format. |
no test coverage detected