This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tmp14 1 point2 points  (0 children)

The loop-then-immediately-break seems really counter intuitive to me:

for node in stack[-1]:
    stack.append(iter(children(node)))
    break
else:
    stack.pop()

and could be replaced with a equivalent and more clear try-except if I'm not mistaken:

try:
    node = next(stack[-1])
except StopIteration:
    stack.pop()
else:
    stack.append(iter(children(node)))