Shortcut to creating an adjacency matrix
<p>I need a short and sweet version of the python code I wrote. So basically what I have is a text file with values such as below:</p>

<pre><code>x
a b c
d e f
</code></pre>

<p>First line is the number of nodes. From second line, the values are read into NODE1, NODE2, Weight. I am taking these values and creating an adjacency matrix out of it. This will be an undirected graph so matrix[u][v] will equal matrix[v][u].
This is the code I have :</p>

<pre><code>with open(filename, 'r') as textfile:
            firstLine = int(textfile.readline())
            for line in textfile:
                a, b, c = line.split()
                a = int(a)
                b = int(b)
                c = float(c)
                graph[a][b] = graph[b][a] = c
</code></pre>

<p>Now I need to populate the diagonals as zero, and other unassigned indices to infinity. </p>