Is there a functional way to do this?

Posted by Ishpeck on Stack Overflow See other posts from Stack Overflow or by Ishpeck
Published on 2010-03-18T16:09:47Z Indexed on 2010/03/18 17:11 UTC
Read the original article Hit count: 259

Filed under:
|
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

© Stack Overflow or respective owner

Related posts about python

Related posts about sequences