code: def recgen(gen, fix_type_errors=True):
      
      if not hasattr(gen,'__iter__'):
          yield gen
      else:
          try:
              for i in gen:
                  for ii in recgen(i):
                      yield ii
          except TypeError:
              # oops, it seems it was not an iterable even if it had an __iter__ method...
              # this happens eg. with theano tensor variables as they try to trick you to sum them.
              if not fix_type_errors:
                  raise # maybe you want this Exception?
              yield gen
docs: Iterates through generators recursively and flattens them.
  
          If `fix_type_errors` is True, `TypeError`s that are generated by
          iterating are ignored and the generator that raised the Exception
          is yielded instead. This is the case eg. for theano tensor variables.
  
          If you want `TypeError`s to be re-raised, set `fix_type_errors` to False.
  
  
          Aliases for this function: `generate_recursively` and `flatten_generator`.
  
          `recgen_enumerate` enumerates the result with tuples corresponding to each index used.