def flattened_iterator(l, types=(list, tuple)):
 if (not isinstance(l, types)):
  (yield l)
  return
 for element in l:
  for sub_element in flattened_iterator(element, types):
   (yield sub_element)

def flattened_iterator ( l , types = ( list , tuple ) ) : if ( not isinstance ( l , types ) ) : ( yield l ) return for element in l : for sub_element in flattened_iterator ( element , types ) : ( yield sub_element )
generator for a list/tuple that potentially contains nested/lists/tuples of arbitrary nesting that returns every individual non-list/tuple element .