def _level_traverse(root, get_children):
 Q = collections.deque([root])
 while Q:
  v = Q.popleft()
  (yield v)
  Q.extend(get_children(v))

def _level_traverse ( root , get_children ) : Q = collections . deque ( [ root ] ) while Q : v = Q . popleft ( ) ( yield v ) Q . extend ( get_children ( v ) )
traverse a tree in breadth-first order .