
Greg Ewing wrote:
This is only a speed issue if the time taken to find the "top" starting from one of the "bottoms" is a significant component of the total running time. My conjecture is that it won't be, especially if you do it iteratively in a tight C loop.
Could it be possible to design it so that the yield path of generators are passed down or forwarded to sub-generators when they are called? If that can be done then no matter how deep they get, it works as if it is always only one generator deep. So... result = yield from sub-generator Might be sugar for ... (very rough example) sub-generator.forward(this_generator_yield_path) # set yield path sub_generator.run() # pass control to sub-generator result = sub_generator.return_value # get return value if set Of course the plumbing in this may takes some creative rewriting of generators so the yield path can be passed around. Being able to get the yield path might also be useful in other ways, such as error reporting. Cheers, Ron