一个报错
>>>list=, [, 4, [[, 7], 8]], 9]def deep_flatten(lst):
result = []
for i in lst:
if isinstance(i, list):
result.extend(deep_flatten(i))
else:
result.append(i)
return result
deep_flatten(list)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
deep_flatten(list)
File "<pyshell#4>", line 4, in deep_flatten
if isinstance(i, list):
TypeError: isinstance() arg 2 must be a type or tuple of types 求大佬帮忙看下,谢谢{:10_277:} list 是Python 的内置函数 你把他赋值了还怎么用 isinstance 判断类型呢?
list1=, [, 4, [[, 7], 8]], 9]
def deep_flatten(lst):
result = []
for i in lst:
if isinstance(i, list):
result.extend(deep_flatten(i))
else:
result.append(i)
return result
deep_flatten(list1) {:10_266:}
页:
[1]