def iterate_depthfirst(obj, opts):
 children = obj.get_children(**opts)
 if (not children):
  return [obj]
 stack = deque([obj])
 traversal = deque()
 while stack:
  t = stack.pop()
  traversal.appendleft(t)
  for c in t.get_children(**opts):
   stack.append(c)
 return iter(traversal)

def iterate_depthfirst ( obj , opts ) : children = obj . get_children ( ** opts ) if ( not children ) : return [ obj ] stack = deque ( [ obj ] ) traversal = deque ( ) while stack : t = stack . pop ( ) traversal . appendleft ( t ) for c in t . get_children ( ** opts ) : stack . append ( c ) return iter ( traversal )
traverse the given expression structure .