You are reading a single comment by @wence and its replies.
Click here to read the full conversation.
-
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).
Now I think your original comment was correct as
popshould give you the last element, right?