Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Graph Representation In Python. Key is vertice name and value is set of neighbouring vertices.
graph = {'A' : set(['G','B']),
'B' : set(['C','D','A']),
'C' : set(['F','D','B']),
'D' : set(['B','C']),
'E' : set(['F']),
'F' : set(['E','C']),
'G' : set(['A']),
print graph
##Output should be {'A': set(['B', 'G']), 'C': set(['B', 'D', 'F']),
## 'B': set(['A', 'C', 'D']), 'E': set(['F']), 'D': set(['C', 'B']),
## 'G': set(['A']), 'F': set(['C', 'E'])}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment