如何把嵌套的python list转成一个一维的python list
展开全部
# coding: utf-8
def some_list_to_one(the_list):
result = list()
for d in the_list:
if type(d) == list:
result += some_list_to_one(d)
else:
result.append(d)
return result
if __name__ == "__main__":
a = [1, [2, [5, [7, 8], 6], 3], 4]
print some_list_to_one(a)
def some_list_to_one(the_list):
result = list()
for d in the_list:
if type(d) == list:
result += some_list_to_one(d)
else:
result.append(d)
return result
if __name__ == "__main__":
a = [1, [2, [5, [7, 8], 6], 3], 4]
print some_list_to_one(a)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询