取嵌套列表中的元素
b=[1,2,3,[3,4,5,3,[23,23,21,3]],3,4,[32,4,3,3]]
思路:定义函数
遍历列表,如果不是列表类型,取出
是列表,调用函数
b=[1,2,3,[3,4,5,3,[23,23,21,3]],3,4,[32,4,3,3]] c=[] def f(li_st): for i in li_st: if type(i) != list: c.append(i) else: f(i) f(b) print(c) [1, 2, 3, 3, 4, 5, 3, 23, 23, 21, 3, 3, 4, 32, 4, 3, 3]
本文来自博客园,作者:Iving,转载请注明原文链接:https://www.cnblogs.com/SAS-T/p/9383352.html