[Python-ideas] Revised^4 PEP on yield-from

Jacob Holm jh at improva.dk
Fri Feb 20 01:18:24 CET 2009

Antoine Pitrou wrote:

> (and, actually, I don't understand how "yield from" helps for a depth-first
> traversal. Could you post an example of it?)
Antoine, I expect something like:

def traverse_depth_first(tree):
    yield tree.value
    for child in tree.children:
        yield from traverse_depth_first(child)

to be semantically equivalent and *much* easier to read than your version.

If we use the expansion listed in the PEP as the implementation of "yield from", we have the O(n**2) performance mentioned.
I *know* we can do better than that, but I don't (yet) know enough about the python internals to tell you how.

I am +1 on the PEP assuming we find a way around the O(n**2) behavior,  +0.75 if not :)



More information about the Python-ideas mailing list