For example
alist = [[1,2],[10,10],[5,5]]
I want to create a new list that has the average of each lists[nth] element and the lists[n+1] element. where n is the size of the list. I want the it have the behaviour you would expect from the step in range([start],stop,[step]), if the step was 2.
so working backwards from the desired output
output = [[5.5,6],[5,5]]
output = [[(1 + 10)/2 , (2 + 10)/2], [5,5]] # The last list has no matching list, so it remains unchanged
output = [[(alist[0][0] + alist[1][0]) / 2, (alist[0][1] + alist[1][1]) / 2), alist[2],alist[2]
output = alist[nth ][yth] + alist[n + 1][y + 1] ....
I went down several roads attempting to make this work and never hit upon a solution. I feel like something in the iterators module should be helpful.
Any suggestions?
You can do a more memory efficient version with itertools
EDIT: Still not certain what the OP wants for the general cases, but here are a couple of alternatives