Would this work?
Given a nested list as in your case problem:
file1 = [[1.0,2.0,3.0],[3.1,2.1,2.1],[3.4,3.4,4.4]]
file2 = [[1.0,2.0,3.0],[3.1,2.1,2.1],[3.4,3.4,4.4]]
simply concat the nested lists after n files. (order remains so we are good)
comb = file1+file2
Perform your operations in a function so its "modular"
def operate(data,n):#heres the function
if n == 2: #naive way to initialize your output
summary = [[],[]]
elif n == 3:
summary = [[],[],[]]
for index,dat in enumerate(data): #getting index +the list
f = [] #holder for the temp data. habit of overwriting stuff
if index%n == 1: #modulo function lets you do for every n list.
#Good experiment to extend this dynamically for n cases instead of just up to 3
if len(summary[1]) == 0:
summary[1] = dat
else:
for a,b in zip(summary[1],dat): #your zip
f.append(a+b)
summary[1] = f #since its a sum we just do it for each pair and replace
elif index%n == 2:
if len(summary[2])== 0:
summary[2] = dat
else:
for a,b in zip(summary[2],dat):
f.append(a+b)
summary[2] = f
elif index%n == 0:
if len(summary[0])== 0:
summary[0] = dat
else:
for a,b in zip(summary[0],dat):
f.append(a+b)
summary[0] = f
return summary
file1 = [[1.0,2.0,3.0],[3.1,2.1,2.1],[3.4,3.4,4.4]]
file2 = [[1.0,2.0,3.0],[3.1,2.1,2.1],[3.4,3.4,4.4]]
comb = file1+file2
t2 = operate(comb,2)
t3 = operate(comb,3)
print("for every second list sum: ",t2)
print("for every third list sum: ",t3)
Theoretically you can extend this for any set by either programming the cases dynamically but you get the gist of it I think.
Output:
for every second list sum: [[7.5, 7.5, 9.5], [7.5, 7.5, 9.5]]
for every third list sum: [[2.0, 4.0, 6.0], [6.2, 4.2, 4.2], [6.8, 6.8, 8.8]]
Do try to initialize the summary variable nicer. It will be part of your solution for extending the cases to orders >3