from collections.abc import * def flatten(lst, out_lst=None): if out_lst is None: out_lst = [] for i in lst: if isinstance(i, Iterable): # 判断i是否可迭代 flatten(i, out_lst) # 尾数递归 else: out_lst.append(i) # 产生结果 return out_lst