def ConvertNodes(node, from_type, to_type, to_text):
 if (node.getType() == from_type):
  new_node = CreateQueryNode(to_text, to_type)
 else:
  new_node = node
 convert_children = (lambda c: ConvertNodes(c, from_type, to_type, to_text))
 new_node.children = map(convert_children, node.children)
 return new_node

def ConvertNodes ( node , from_type , to_type , to_text ) : if ( node . getType ( ) == from_type ) : new_node = CreateQueryNode ( to_text , to_type ) else : new_node = node convert_children = ( lambda c : ConvertNodes ( c , from_type , to_type , to_text ) ) new_node . children = map ( convert_children , node . children ) return new_node
converts nodes of type from_type to nodes of type to_type .