title: Iterate over array twice (cartesian product) but consider only half the elements
body: <p>I am trying to iterate over an array twice to have pairs of elements (e_i,e_j) but I only want the elements such that i &lt; j.</p>
  
  <p>Basically, what I want would look like this is C-like languages.</p>
  
  <pre><code>int my_array[N] = ...;
  for (int i=0; i&lt;N; i++)
          for (int j=i+1; j&lt;N; j++)
                  something(my_array[i],my_array[j]);
  </code></pre>
  
  <p>I didn't find what I was looking for in <a href="https://docs.python.org/library/itertools.html" rel="nofollow noreferrer">itertools</a> (the closest thing I've found was <code>itertools.product(*iterables[, repeat])</code>).</p>
  
  <p>I tried a few things but I am not really convinced by any of them :</p>
  
  <pre><code>my_list=range(10)
  
  # Using enumerate and slices - explicit loop
  res=[]
  for i,j in enumerate(my_list):
          for k in my_list[i+1:]:
                  res.append((j,k))
  print res
  
  # Using enumerate and slices - list comprehension
  res=[(j,k) for i,j in enumerate(my_list) for k in my_list[i+1:]]
  print res
  
  # Using enumerate and xrange - explicit loop
  res=[]
  for i,j in enumerate(my_list):
          for k in range(i+1, len(my_list)):
                  res.append((j,my_list[k]))
  print res       
  
  # Using enumerate and xrange - list comprehension
  res=[(j,my_list[k]) for i,j in enumerate(my_list) for k in range(i+1, len(my_list))]
  print res
  </code></pre>
  
  <p>I'm still convinced that there is a better and more pythonic solution. Any suggestion is welcome.</p>