title: Converting adjacency list to adjacency matrix in python
body: <blockquote>
    <p>Trying to write a code to convert a graph representation from adjacency list to adjacency matrix.</p>
  </blockquote>
  
  <p>The function should input an adjacency list <code>adj_list = [[1,2],[2],[],[0,1]]</code> and output the binary matrix </p>
  
  <pre><code>adj_mat = [0. 1. 1. 0]
            [0. 0. 1. 0.]
            [0. 0. 0. 0.]
            [1. 1. 0. 0.] 
  </code></pre>
  
  <p>However running the code </p>
  
  <pre><code> def adj_list_to_matrix(adj_list):
      n = len(adj_list)
      adj_matrix = np.nan * np.ones((n,n))
      np.fill_diagonal(adj_matrix,0)
  
      for i in range(n):
          for j, w in adj_list[i]:
              adj_matrix[i,j] = w
      return adj_matrix
  </code></pre>
  
  <p>produces the error message </p>
  
  <pre><code>for j, w in adj_list[i]:
  TypeError: cannot unpack non-iterable int object 
  </code></pre>
  
  <p>Can anyone help resolve this issue to get a working code?</p>