
On 8/13/2010 4:11 AM, Greg Ewing wrote:
That's not actually true -- a for-loop would work with any iterable node object just as well.
I agree that it works, but it does not avoid the recursion-depth problem and you pay for the decent through all of the for-loops. I assume we are both talking about an implementation __iter__() like: def __iter__(self): if self.left: for v in self.left: yield v if self.us: yield self.us if self.right: for v in self.right: yield v But this fails with a recursion depth RuntimeError around a depth of ~1000 or so. Perhaps that is not an interesting practical problem. But, my comment about it being "complicated and verbose" was that to avoid that depth problem, the obvious solution is to make __iter__() implement an in-order stack itself and manufacturer some way to deal with other types being in the tree. But again, due to how deep of a structure you need, perhaps it's not that interesting. -- Scott Dial scott@scottdial.com scodial@cs.indiana.edu