I am trying to create a program that inserts a list in the middle of another nested list. Like a sandwich sandwiching another sandwich and so on. I am trying to approach this recursively but I have no idea how.
for example
layer1 = [1,2,3,4]
layer2 = [1,2,3,4,5,6]
layer3 = [1,2,3]
output = [1,2,[1,2,3,[1,2,3],4,5,6],3,4]
Here's my code for context
def lasagna(N,i):
mainLayers = formLayer(i)
midpoint = len(mainLayers) // 2
if i == N:
return mainLayers
elif i < N:
mainLayers = mainLayers.insert(midpoint, formLayer(i))
return lasagna(N,i+1)