Recursive function going infinite and I can't see why.
Terry Reedy
tjreedy at udel.edu
Sat Feb 4 03:22:39 EST 2006
>Would anyone be able to tell me why my function below is getting stuck
>in infinite recusion?
>def replace_within_node(node,oldnode,newnode):
> if node is oldnode:
> return newnode
Without looking further, the most likely reason is that the base case is
never true: ie, node is never oldnode. I would probably add
print node, oldnode, newnode
at the top (and maybe another print later) and then run the code on a small
tree where I thought I knew what should be printed and then see where my
expectation diverges from the actual.
Terry Jan Reedy
More information about the Python-list
mailing list