def recursiveLooper(iterators, pos=0):
    """ Implements the same functionality as nested for loops, but is 
        more dynamic. iterators can either be a list of methods which
        return iterables, a list of iterables, or a combination of both.
    """
    nextLoop, v = None, []
    try:
        gen = iter(iterators[pos]())
    except TypeError:
        gen = iter(iterators[pos])
        
    while True:
        try:
            yield v + nextLoop.next()
        except (StopIteration, AttributeError):
            v = [gen.next(),]
                
            if pos < len(iterators) - 1:
                nextLoop = recursiveLooper(iterators, pos + 1)
            else:
                yield v
 Implements the same functionality as nested for loops, but is 
        more dynamic. iterators can either be a list of methods which
        return iterables, a list of iterables, or a combination of both.
    
recipes/Python/577415_Recursive_functireplace_nested_loops/recipe-577415.py