#NEWLINE# def tree_structure( forums ) : #NEWLINE# #INDENT# structure = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( previous , current , next ) in previous_current_next ( forums ) : #NEWLINE# #INDENT# if previous : #NEWLINE# #INDENT# structure [ 'new_level' ] = ( previous . level < current . level ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# structure [ 'new_level' ] = True #NEWLINE# #UNINDENT# if next : #NEWLINE# #INDENT# structure [ 'closed_levels' ] = range ( current . level , current . level , ( - 1 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# structure [ 'closed_levels' ] = range ( current . level , ( - 1 ) , ( - 1 ) ) #NEWLINE# #UNINDENT# ( yield ( current , copy . deepcopy ( structure ) ) )