#NEWLINE# def to_dict( self ) : #NEWLINE# #INDENT# def traverse( node ) : #NEWLINE# #INDENT# ret = node . to_dict ( ) #NEWLINE# ret [ 'children' ] = [ ] #NEWLINE# for child in node . children : #NEWLINE# #INDENT# ret [ 'children' ] . append ( traverse ( child ) ) #NEWLINE# #UNINDENT# return ret #NEWLINE# #UNINDENT# return [ traverse ( root ) for root in traverse . roots ]