#NEWLINE# def powerset_tree( lst , initial = True , terminator = '' ) : #NEWLINE# #INDENT# 'Creates nested powersets of the word list for each key\n    -- the result is effectively a suffix tree.\n    `terminator` is a string value that can be passed in to terminate\n    each parent element in a list -- indices can be used to denote\n    the same thing, but it gives a visual option if you prefer.\n    ' #NEWLINE# if isinstance ( lst , str ) : #NEWLINE# #INDENT# lst = substring_list ( lst ) #NEWLINE# #UNINDENT# for ( k , substr ) in enumerate ( lst ) : #NEWLINE# #INDENT# if initial : #NEWLINE# #INDENT# lst [ k ] = [ ( substr + terminator ) ] #NEWLINE# initial = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( substr ) == 1 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# lst [ k ] = [ ( substr + terminator ) , powerset_tree ( substring_list ( substr [ 1 : ] ) , initial = initial ) ] #NEWLINE# #UNINDENT# #UNINDENT# return lst