Is there a functional way to do this?
- by Ishpeck
def flattenList(toFlatten):
final=[]
for el in toFlatten:
if isinstance(el, list):
final.extend(flattenList(el))
else:
final.append(el)
return final
When I don't know how deeply the lists will nest, this is the only way I can think to do this. 2