def _flatten(tuple):
 res = ()
 for item in tuple:
  if (type(item) in (TupleType, ListType)):
   res = (res + _flatten(item))
  elif (item is not None):
   res = (res + (item,))
 return res

def _flatten ( tuple ) : res = ( ) for item in tuple : if ( type ( item ) in ( TupleType , ListType ) ) : res = ( res + _flatten ( item ) ) elif ( item is not None ) : res = ( res + ( item , ) ) return res
generator function going deep in tree-like structures and returning all elements as a flat list .