def nest2list(l1):
for i in l1:
if isinstance(i, list):
nest2list(i)
else:
new_foo.append(i)
if __name__ == '__main__':
foo = [1, 2, [3, [[5, 6], 7], 8], 9]
new_foo = list()
nest2list(foo)
print(new_foo)
[1, 2, 3, 5, 6, 7, 8, 9]
Process finished with exit code 0
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |