I wanted to create a data structure that can store the name of a vertex, vertices it is adjacent to along with the edge weight. I thought of creating a dict that maps a vertex to a list that further has dict to store vertices it is adjacent to with edge weight.
In other words:
D = {
vertex1: [
{
Adj_vertex1: edge weight
},
{
Adj_vertex2: edge weight
}
]
}
Is there an effective way to do this? Also, if I use the structure above how do I access Adj_vertex2?
D = {vertex1: {Adj_vertex1: weight, Adj_vertex2: weight}}then access is as simple asD[vertex1][Adj_vertex2]but is more likely to be used in a loopfor a_v, w in D[vertex1].items():