I'm still learning to work with objects. I defined vertices() as a method to return the vertices (initialized as vs) in Graph. I know that there is a more concise, elegant way to write vertices() but exactly how is escaping me.
Also specifically this relates to exercise 2.5 in Think Complexity: http://greenteapress.com/complexity/html/book003.html#toc12
class Graph(dict):
def __init__(self, vs=[], es=[]):
for v in vs:
self.add_vertex(v)
def add_vertex(self, v):
"""Add a vertex to the graph."""
self[v] = {}
def vertices(self):
v = []
for i in range(len(self)):
v.append(i)
return v