layer2 = []
while True:
    for i in layer1:
        if isinstance(i, list):
            for j in i:
                layer2.append(j)
else:
    print(i)
layer1[:] = layer2
layer2 = []
if len(layer1) == 0:
    break
Python - Iterating through list of list