Skip to content

Instantly share code, notes, and snippets.

@john-nash-rs
Created July 7, 2018 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john-nash-rs/40f025641a8b5f6dadfb2efd6cd4dd50 to your computer and use it in GitHub Desktop.
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.
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