def flatten(*stack):
    """
    helper function for flattening iterables of generators in a
    sensible way.
    """
    stack = list(stack)
    while stack:
        try: x = next(stack[0])
        except __HOLE__:
            stack.pop(0)
            continue
        if hasattr(x,'next') and callable(getattr(x,'next')):
            stack.insert(0, x)

        #if isinstance(x, (GeneratorType,listerator)):
        else: yield x
dataset/ETHPy150Open pydata/pandas/scripts/json_manip.py/flatten