title: Get information out of sub-lists in main list elegantly
body: <p>Ok, so here's my issue. I have a list composed of <code>N</code> sub-lists composed of <code>M</code> elements (floats) each. So in a general form it looks like this:</p>
  
  <pre><code>a_list = [b_list_1, b_list_2, ..., b_list_N]
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>b_list_i = [c_float_1, c_float_2, ..., c_float_M]
  </code></pre>
  
  <p>For this example assume <code>N=9 ; M=3</code>, so the list looks like this:</p>
  
  <pre><code>a = [[1.1, 0.5, 0.7], [0.3, 1.4, 0.2], [0.6, 0.2, 1.], [1.1, 0.5, 0.3], [0.2, 1.1, 0.8], [1.1, 0.5, 1.], [1.2, 0.3, 0.6], [0.6, 0.4, 0.9], [0.6, 0.2, 0.5]]
  </code></pre>
  
  <p>I need to loop through this list identifying those items that <em>share the same first two floats</em> as the same item where the third float should be averaged before storing. This means I should check if an item was already identified as being repeated previously, so I do not identify it again as a new item.</p>
  
  <p>To give a more clear idea of what I mean, this is what the output of processing list <code>a</code> should look like:</p>
  
  <pre><code>a_processed = [[1.1, 0.5, 0.67], [0.3, 1.4, 0.2], [0.6, 0.2, 0.75], [0.2, 1.1, 0.8], [1.2, 0.3, 0.6], [0.6, 0.4, 0.9]]
  </code></pre>
  
  <p>Note that the first item in this new list was identified three times in a (<code>a[0]</code>, <code>a[3]</code> and <code>a[5]</code>) and so it was stored with its third float averaged (<code>(0.7+0.3+1.)/3. = 0.67</code>). The second item was not repeated in <code>a</code> so it was stored as is. The third item was found twice in <code>a</code> (<code>a[2]</code> and <code>a[8]</code>) and stored with its third float averaged (<code>(1.+0.5)/2.=0.75</code>). The rest of the items in the new list were not found as repeated in <code>a</code> so they were also stored with no modifications.</p>
  
  <p>Since I know updating/modifying a list while looping through it is not recommended, I opted to use several temporary lists. This is the code I came up with:</p>
  
  <pre><code>import numpy as np
  
  a = [[1.1, 0.5, 0.7], [0.3, 1.4, 0.2], [0.6, 0.2, 1.], [1.1, 0.5, 0.3],
       [0.2, 1.1, 0.8], [1.1, 0.5, 1.], [1.2, 0.3, 0.6], [0.6, 0.4, 0.9],
  [0.6, 0.2, 0.5]]
  
  # Final list.
  a_processed = []
  
  # Holds indexes of elements to skip.
  skip_elem = []
  
  # Loop through all items in a.
  for indx, elem in enumerate(a):
      temp_average = []
      temp_average.append(elem)        
      # Only process if not found previously.
      if indx not in skip_elem:
          for indx2, elem2 in enumerate(a[(indx+1):]):
              if elem[0] == elem2[0] and elem[1] == elem2[1]:
                  temp_average.append(elem2)
                  skip_elem.append(indx2+indx+1)
  
          # Store 1st and 2nd floats and averaged 3rd float.
          a_processed.append([temp_average[0][0], temp_average[0][1],
                              round(np.mean([i[2] for i in temp_average]),2)])
  </code></pre>
  
  <p>This code works, but I'm wondering if there might be a more elegant/pythonic way of doing this. It just looks too convoluted (Fortran-esque I'd say) as is.</p>