#NEWLINE# def flatten( l ) : #NEWLINE# #INDENT# '\n    Turns a nested graph of lists/tuples/other objects into a list of objects.\n\n    Parameters\n    ----------\n    l : list/tuple/other objects\n        Might be nested.\n\n    Returns\n    -------\n    object\n        A flattened list of objects.\n\n    ' #NEWLINE# if isinstance ( l , ( list , tuple , collections . ValuesView ) ) : #NEWLINE# #INDENT# rval = [ ] #NEWLINE# for elem in l : #NEWLINE# #INDENT# if isinstance ( elem , ( list , tuple ) ) : #NEWLINE# #INDENT# rval . extend ( flatten ( elem ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rval . append ( elem ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return [ l ] #NEWLINE# #UNINDENT# return rval