title: Average of elements in a 2d list
body: <p>I have a list like the following:</p>
  
  <pre><code>[[1, 1], [7, 7], [20, 20], [9, 9], [-12, -12]] 
  </code></pre>
  
  <p>And I'm trying to have a new list which has the same number of lists inside, but changes the value of the elements by calculating the average of an element with the element after and before.
  What do I mean by that ?:
  Let's say I have the sub-list sub = [7,7]
  at index 1. I want this list to be [9,9], because sub[1][0] + lst_before_sub[0][0] + lst_after_sub[1][0] = 7 + 1 + 20 = 28, and 28//3 = 9 (I want integer divison).</p>
  
  <p>The ideal output would be: </p>
  
  <pre><code>[[4, 4], [9, 9], [12, 12], [5, 5], [-1, -1]] 
  </code></pre>
  
  <p>I have currently this code: </p>
  
  <pre><code>copy_l = copy.deepcopy(audio_data)
  sub_list = []
  for i in range(0, len(audio_data)-1):
      sub_data = []
      for j in range(2):
          if i == 0:
              audio_data[i][j] += int(audio_data[i+1][j] / 2)
              sub_data.append(audio_data[i][j])
          elif audio_data[i+1] == audio_data[-1]:
              audio_data[i+1][j] = int((audio_data[i+1][j]+audio_data[i][j])/2)
              sub_data.append(audio_data[i+1][j])
          else:
              audio_data = copy_l
              audio_data[i][j] = int((audio_data[i-1][j] + audio_data[i][j] + audio_data[i+1][j])/3)
              sub_data.append(audio_data[i][j])
      sub_list.append(sub_data)
  print(sub_list)
  </code></pre>
  
  <p>where audio_data is the list [[1, 1], [7, 7], [20, 20], [9, 9], [-12, -12]] that I passed in.</p>
  
  <p>(I have separated the average calculation in three cases:
  - First element of the list: [1,1] so the average is just 1 + 7 // 2 (no element before [1,1])
  - Last element of the list: [-12,-12] so the average is just -12 + 9 // 2 (no element after [-12,-12])
  - All the elements in between
  )</p>
  
  <p>Problem is, my output (sub_list) is: 
  <code>[[4, 4], [9, 9], [12, 12], [-1, -1]]</code>
  And it seems that [9,9] never turns into [5,5]
  Does someone have any idea how to achieve what I want, or even an idea to make it simpler ? I hope I was clear enough, if not feel free to ask me more details, thank you!</p>
  
  <p><strong>EDIT:</strong>
  I'm seeking a solution without numpy, list comprehension or zip.</p>