Sadly as far as I know there's no way to really blindly unpack an indefinitely nested list in python.
Op appears to have attempted to copy from
Making a flat list out of list of lists in Python
flatten = lambda l: [item for sublist in l for item in sublist]
I tested the above on python 3.6, four-nested structure. Sadly it only unpacks the outer layer. I need to use it in a loop three times to fully unpack the structure.
import numpy as np
x = np.arange(625).reshape(5,5,5,-1).tolist() #4-nested structure
flatten = lambda x: [item for sublist in x for item in sublist]
y = flatten(x) #results in 3-nested structure of length 25.
The same problem also exists for the more versatile below function (which requires an import):
from itertools import chain
y = list(chain.from_iterable(x)) #as per flatten() above, unpacks one level
For multiple layers and if you're not too concerned about overhead, you could just do the following:
import numpy as np
y = np.array(x).flatten().tolist() #where x is any list / tuple / numpy array /
#iterable
Hope the above helps :)
p.s. Ahsanul Hafique's unpacking illustrates the logic of the lambda function as requested by op. I don't believe in lambda functions and you just have to look at Ahsanul's unpacking to see why. It would be trivial to factor out the unpacking , while in the main function check if the sublist is a list or list element, and unpack or append as appropriate and thus create a completely versatile list unpacker using two functions.