I am very new to Python, but it seems that your problem should be represented by a nxn matrix for n nodes. Let each entry in the matrix represent the weight between each node in the column to each node in the row. So you would represent the distance between nodes 1 to 2 with a 3 in that location. Now, Python does not have arrays, but you could do this with lists.
After initializing this list to 0, you could assign something like this:
network[1][2]=3
network[2][1]=3
network[1][4]=5
network[4][1]=5
write your row and column operations to add the weights by traversing the matrix, starting at the node row, then switch node row with the column, and trying again. If you can NOT find a connection other than where you were on the previous iteration, then you are at an end, and will need to start at a new node and repeat the process. I would do an iteration on each row, and print out a table of nodes and weight sums. Hope that this gives you some ideas.
Hope I answered your question. I am a mathematician, but an amateur with Python.