parameters: (tree, visitor)
docstring: depth first search on a dict.
      call the visit(elem) method on the visitor for each node
  
      if the visitor returns True, stop the search
docstring_summary: depth first search on a dict.
      call the visit(elem) method on the visitor for each node
docstring_tokens: depth first search on a dict . call the visit ( elem ) method on the visitor for each node
function: def walk_dict(tree, visitor):
      """
      depth first search on a dict.
      call the visit(elem) method on the visitor for each node
  
      if the visitor returns True, stop the search
  
      """
      queue = deque()
  
      def add_elt(name, elt, first=False):
          if isinstance(elt, (list, tuple)):
              for val in elt:
                  queue.append((name, val))
          elif hasattr(elt, 'items'):
              for k, v in elt.items():
                  queue.append((k, v))
          elif first:  # for the first elt, we add it even if it is no collection
              queue.append((name, elt))
  
      add_elt("main", tree, first=True)
      while queue:
          elem = queue.pop()
          # we don't want to visit the list, we'll visit each node separately
          if not isinstance(elem[1], (list, tuple)):
              if visitor(elem[0], elem[1]) is True:
                  # we stop the search if the visitor returns True
                  break
          # for list and tuple, the name is the parent's name
          add_elt(elem[0], elem[1])
function_tokens: def walk_dict ( tree , visitor ) : queue = deque ( ) def add_elt ( name , elt , first = False ) : if isinstance ( elt , ( list , tuple ) ) : for val in elt : queue . append ( ( name , val ) ) elif hasattr ( elt , 'items' ) : for k , v in elt . items ( ) : queue . append ( ( k , v ) ) elif first : # for the first elt, we add it even if it is no collection queue . append ( ( name , elt ) ) add_elt ( "main" , tree , first = True ) while queue : elem = queue . pop ( ) # we don't want to visit the list, we'll visit each node separately if not isinstance ( elem [ 1 ] , ( list , tuple ) ) : if visitor ( elem [ 0 ] , elem [ 1 ] ) is True : # we stop the search if the visitor returns True break # for list and tuple, the name is the parent's name add_elt ( elem [ 0 ] , elem [ 1 ] )