def spread_list(li): res = [] for l in li: if not isinstance(l, list): res.append(l) else: res.extend(spread_list(l)) return res 2016-10-20 回复1 张新丰 python cookbookfrom collections import Iterabledef flatten(items,ignore_types=(str,bytes)): for x in items: if isi...
嵌套list的展开python eg: input:[1, 3,[5, 6, [9, 10], [11,[12, [13, 14]]], 15]] output:[1, 3, 5, 6, 9, 10, 11, 12, 13, 14, 15] classFlatList(object):def__init__(self):self.res=[]defrun(self,big_list):ifnotisinstance(big_list,list):returnforiteminbig_list:i...