import sys
input_list=[1,[2,3,4,[5],6]]
def muchlist2onelist(input_list,res):
for i in input_list:
if isinstance(i,list):
muchlist2onelist(i,res) #在这里使用递归求解,递归不只是在最后才可以使用。
else:
res.append(i)
return res
if __name__=='__main__':
res=[]
print(muchlist2onelist(input_list,res))
参考连接:
https://blog.csdn.net/SeeTheWorld518/article/details/46756355
https://blog.csdn.net/XX_123_1_RJ/article/details/80591107