嵌套列表转换为单列表
1.递归实现
a = [1,[2,[3],4],5]def list_more(arg): new_list = [] for i in arg: if type(i) is not list: new_list.append(i) else: new_list.extend(list_more(i)) return new_listIn [65]: list_more(a)Out[65]: [1, 2, 3, 4, 5]
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。