#将列表中的元素保存到一个列表中
l=[1,[2,[3,[4,[5,[6,7,8]]]]]]
new_l=[]deffunc1(l):for i in l:iftype(i)islist:
func1(i)else:
new_l.append(i)return new_l
print(func1(l))
函数递归 函数递归的两个过程:递推、回溯 python中得函数随着每次递归得增加,会占用相应得内存空间;python中默认得递归次数限制为1000#将列表中的元素保存到一个列表中l=[1,[2,[3,[4,[5,[6,7,8]]]]]]new_l=[]def func1(l): for i in l: if type(i) is list: func1(i) else: new_l.append(i)