Skip to content

Instantly share code, notes, and snippets.

@MLWhiz
Last active June 13, 2019 15:24
Show Gist options
  • Save MLWhiz/a8bfb10a3101c45493934d8c1bd8c662 to your computer and use it in GitHub Desktop.
Save MLWhiz/a8bfb10a3101c45493934d8c1bd8c662 to your computer and use it in GitHub Desktop.
g = { "a" : {"d":2},
"b" : {"c":2},
"c" : {"b":5, "d":3, "e":5}
}
graph = Graph(g)
print("Vertices of graph:")
print(graph.vertices())
print("Edges of graph:")
print(graph.edges())
print("Add vertex:")
graph.add_vertex("z")
print("Vertices of graph:")
print(graph.vertices())
print("Add an edge:")
graph.add_edge({"a","z"})
print("Vertices of graph:")
print(graph.vertices())
print("Edges of graph:")
print(graph.edges())
print('Adding an edge {"x","y"} with new vertices:')
graph.add_edge({"x","y"})
print("Vertices of graph:")
print(graph.vertices())
print("Edges of graph:")
print(graph.edges())
@bryaniou
Copy link

graph = Graph (g)

in this line I get that it is not defined and I do not execute
I am new at this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment