• That's true, but think about when you would naturally process an entry in the stack:

    lifo = [n]
    seen = {n}
    while lifo:
        node = lifo.pop()
        yield node # <- parent appears before child in iteration
        for c in node.children:
           if c not in seen:
               seen.add(c)
               lifo.append(c)
    

    If you care about a strict left-to-right order of children in a tree-like structure you would walk over reversed(node.children).

About

Avatar for frankenbike @frankenbike started