#NEWLINE# def _layout_to_matrix( layout ) : #NEWLINE# #INDENT# 'Create the adjacency matrix for the tree specified by the\n    given layout (level sequence).' #NEWLINE# result = [ ( [ 0 ] * len ( layout ) ) for i in range ( len ( layout ) ) ] #NEWLINE# stack = [ ] #NEWLINE# for i in range ( len ( layout ) ) : #NEWLINE# #INDENT# i_level = layout [ i ] #NEWLINE# if stack : #NEWLINE# #INDENT# j = stack [ ( - 1 ) ] #NEWLINE# j_level = layout [ j ] #NEWLINE# while ( j_level >= i_level ) : #NEWLINE# #INDENT# stack . pop ( ) #NEWLINE# j = stack [ ( - 1 ) ] #NEWLINE# j_level = layout [ j ] #NEWLINE# #UNINDENT# result [ i ] [ j ] = result [ j ] [ i ] = 1 #NEWLINE# #UNINDENT# stack . append ( i ) #NEWLINE# #UNINDENT# return result