#NEWLINE# def flatten( root , visited = None ) : #NEWLINE# #INDENT# if ( not visited ) : #NEWLINE# #INDENT# visited = set ( ) #NEWLINE# #UNINDENT# ( yield root ) #NEWLINE# for component in root . components . copy ( ) : #NEWLINE# #INDENT# if ( component not in visited ) : #NEWLINE# #INDENT# visited . add ( component ) #NEWLINE# for child in flatten ( component , visited ) : #NEWLINE# #INDENT# ( yield child )