title: conditional sum over a range python
body: <p>I have created X as folowing</p>
  
  <pre><code>num_locations = 2
  X= [ ]
  for n in range(num_locations):
  X.append([0 for j in range(num_locations)])
  </code></pre>
  
  <p>Now I want to sum these X[n][m] values for the case n != m . Such that the result should be like</p>
  
  <pre><code>X[0][1]+X[1][0]
  </code></pre>
  
  <p>Is there a way to do that with the sum formulation ?</p>
  
  <pre><code>X[n][m] for n in range(num_locations)for m in range(num_locations))
  </code></pre>