Changing self: if self is a tree how to set to a different self

Terry Reedy tjreedy at
Sat Jul 12 21:43:03 CEST 2008

Kay Schluehr wrote:
> Since it is acting on a tree why doesn't the code substitute self in
> its parent by SS? That's the natural perspective if one considers a
> tree as a linked structure and inserts and deletes nodes within this
> structure.

I think you are suggesting the same thing I did:

 > If you examine nodes from their parent, I believe you can do the
 > > substitution in one step. Something like:
 > >
 > > for slot,child in ( ('left',self.left), ('right',self.right) ):
 > >   if child is not None:
 > >     if child.val == 'f':
 > >       setattr(self, slot, F.copy().subst('x', child.left))
 > >     child.elimF
 > >
 > > where .subst returns the modified tree.

Where F.copy is what was called 'SS'.  If not, I don't understand.

More information about the Python-list mailing list