def flatten(l):
    if isinstance(l, (list, tuple, collections.ValuesView)):
        rval = []
        for elem in l:
            if isinstance(elem, (list, tuple)):
                rval.extend(flatten(elem))
            else:
                rval.append(elem)
    else:
        return [l]
    return rval
Turns a nested graph of lists/tuples/other objects into a list of objects.
dataset/ETHPy150Open rizar/attention-lvcsr/libs/Theano/theano/compile/nanguardmode.py/flatten