python算法:嵌套数组转变成一维数组
2017-07-03 16:10 很大很老实 阅读(3264) 评论(0) 编辑 收藏 举报比如,输入是:[2, 1, [3, [4, 5], 6], 7, [8]]
则,输出是:[2, 1, 3, 4, 5, 6, 7, 8]
def list_flatten(l, a=None): a = list(a) if isinstance(a, (list, tuple)) else [] for i in l: if isinstance(i, (list, tuple)): a = list_flatten(i, a) else: a.append(i) return a