import functools


def nest(*iterables):
    """Flatten nested for loops it a single tuple yielding generator.

    Useful in that it prevents over indentation.
    Source: http://code.activestate.com/recipes/473818/#c1

    Thus:
    for i, j, c in nest(range(10), range(10), "ABCDEF"):
        do_something(i, j, c)

    Is equivalent to:
    for i in range(10):
        for j in range(10):
            for c in "ABCDEF":
                do_something(i, j, c)
    """
    def _nest(outer, inner):
        for outer_item in outer:
            if not isinstance(outer_item, tuple):
                outer_item = (outer_item,)
            for inner_item in inner:
                yield outer_item + (inner_item,)
    return functools.reduce(_nest, iterables)