This handles both of your cases, and I think will solve the general case, without any for loops:
def flatten(S):
if S == []:
return S
if isinstance(S[0], list):
return flatten(S[0]) + flatten(S[1:])
return S[:1] + flatten(S[1:])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…