Created
July 7, 2018 19:00
-
-
Save john-nash-rs/40f025641a8b5f6dadfb2efd6cd4dd50 to your computer and use it in GitHub Desktop.
Graph Representation In Python. Key is vertice name and value is set of neighbouring vertices.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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