It works just like os.walk, but you can pass it a level parameter
        that indicates how deep the recursion will go.
        If depth is -1 (or less than 0), the full depth is walked.
502921
def walklevel(path, depth = -1, **kwargs):
        
        # if depth is negative, just walk
        if depth < 0:
            for root, dirs, files in os.walk(path, **kwargs):
                yield root, dirs, files

        # path.count works because is a file has a "/" it will show up in the list
        # as a ":"
        path    = path.rstrip(os.path.sep)
        num_sep = path.count(os.path.sep)
        for root, dirs, files in os.walk(path, **kwargs):
            yield root, dirs, files
            num_sep_this = root.count(os.path.sep)
            if num_sep + depth <= num_sep_this:
                del dirs[:]
464145
def depth(sequence, func=max, _depth=0):
    
    if isinstance(sequence, dict):
        sequence = list(sequence.values())
    depth_list = [depth(item, func=func, _depth=_depth + 1)
                  for item in sequence if (isinstance(item, dict) or util_type.is_listlike(item))]
    if len(depth_list) > 0:
        return func(depth_list)
    else:
        return _depth
952754
def _walk(self):
        """"""

        self._base_len = len(self.base)

        for base, dirs, files in os.walk(self.base, followlinks=self.follow_links):
            # Remove child folders based on exclude rules
            for name in dirs[:]:
                try:
                    if not self._valid_folder(base, name):
                        dirs.remove(name)
                except Exception:
                    dirs.remove(name)
                    value = self.on_error(base, name)
                    if value is not None:  # pragma: no cover
                        yield value

                if self._abort:
                    break

            # Search files if they were found
            if len(files):
                # Only search files that are in the include rules
                for name in files:
                    try:
                        valid = self._valid_file(base, name)
                    except Exception:
                        valid = False
                        value = self.on_error(base, name)
                        if value is not None:
                            yield value

                    if valid:
                        yield self.on_match(base, name)
                    else:
                        self._skipped += 1
                        value = self.on_skip(base, name)
                        if value is not None:
                            yield value

                    if self._abort:
                        break

            if self._abort:
                break
806851
function getLowestCommonAncestor(instA, instB) {
  var depthA = 0;
  for (var tempA = instA; tempA; tempA = getParent(tempA)) {
    depthA++;
  }
  var depthB = 0;
  for (var tempB = instB; tempB; tempB = getParent(tempB)) {
    depthB++;
  }

  // If A is deeper, crawl up.
  while (depthA - depthB > 0) {
    instA = getParent(instA);
    depthA--;
  }

  // If B is deeper, crawl up.
  while (depthB - depthA > 0) {
    instB = getParent(instB);
    depthB--;
  }

  // Walk in lockstep until we find a match.
  var depth = depthA;
  while (depth--) {
    if (instA === instB || instA === instB.alternate) {
      return instA;
    }
    instA = getParent(instA);
    instB = getParent(instB);
  }
  return null;
}
217048
private int depth() {
        int i = 0;
        for (TreeString p = this; p != null; p = p.parent) {
            i++;
        }
        return i;
    }
640359
function walk(node, callback)
{
	var childNode,i;
	
	if (callback(node) === false) return false;
	
	if (node.childNodes != null)
	{
		i = 0;
		childNode = node.childNodes[i];
	}
	
	while (childNode != null)
	{
		if (walk(childNode, callback) === false) return false;
		
		childNode = node.childNodes[++i];
	}
}
379246
def _do_stack(self, cmd, args):
        
        if not args:
            self.__dump_stack()
            return
        if len(args) > 1:
            self.stderr.write('stack: too many arguments: {}\n'.format(args))
            return
        try:
            depth = int(args[0])
        except ValueError:
            self.stderr.write("stack: depth is not an integer: '{}'\n".format(args[0]))
            return
        if depth < 0:
            self.stderr.write('stack: negative depth: {}\n'.format(depth))
            return
        return depth
1351060
function (callback, ctx) {
            var _walk = function (depth, node, ctx) {
                if (typeof callback === "function")
                    ctx = callback(depth, node, ctx, false);
                var children = node.children();
                for (var i = 0; i < children.length; i++)
                    ctx = _walk(depth + 1, children[i], ctx);
                if (typeof callback === "function")
                    ctx = callback(depth, node, ctx, true);
                return ctx;
            };
            ctx = _walk(0, this, ctx);
            return ctx;
        }
1270507
def depth_first_recurse(node = nil, depth = 0, &block)
      node = self if node == nil
      yield node, depth
      node.children.each do |child|
        depth_first_recurse(child, depth+1, &block)
      end
    end
265459
def walk_dir(path, args, state):
    
    if args.debug:
        sys.stderr.write("Walking %s\n" % path)

    for root, _dirs, files in os.walk(path):
        if not safe_process_files(root, files, args, state):
            return False
        if state.should_quit():
            return False
    return True
557609
def allows_recursion (self):
        
        log.debug(LOG_CHECK, "checking recursion of %r ...", self.url)
        if not self.valid:
            log.debug(LOG_CHECK, "... no, invalid.")
            return False
        if not self.can_get_content():
            log.debug(LOG_CHECK, "... no, cannot get content.")
            return False
        if not self.allows_simple_recursion():
            return False
        if self.size > self.aggregate.config["maxfilesizeparse"]:
            log.debug(LOG_CHECK, "... no, maximum parse size.")
            return False
        if not self.is_parseable():
            log.debug(LOG_CHECK, "... no, not parseable.")
            return False
        if not self.content_allows_robots():
            log.debug(LOG_CHECK, "... no, robots.")
            return False
        log.debug(LOG_CHECK, "... yes, recursion.")
        return True
711901
function (array, c, depth) {
        var start = array.length - (array.length / Math.pow(2, depth));
        for (var i = start, len = array.length; i < len; i += 1) {
            array[i] += c;
        }
    }
740372
def walk(self, top, file_list={}):
        """"""
        for root, dirs, files in os.walk(top, topdown=False):
            if os.path.basename(root) in self.ignore_dirs:
                # Do not dig in ignored dirs
                continue

            for name in files:
                full_path = os.path.join(root, name)
                if self.include(full_path):
                    if os.path.isfile(full_path):
                        # preventing fail if the file vanishes
                        content = open(full_path).read()
                        hashcode = hashlib.sha224(content).hexdigest()
                        file_list[full_path] = hashcode
            for name in dirs:
                if name not in self.ignore_dirs:
                    self.walk(os.path.join(root, name), file_list)
        return file_list
1373993
public int depth() {
        if (isLeaf()) {
            return 0;
        }
        int maxDepth = 0;
        List<Tree> kids = children();
        for (Tree kid : kids) {
            int curDepth = kid.depth();
            if (curDepth > maxDepth) {
                maxDepth = curDepth;
            }
        }
        return maxDepth + 1;
    }
161403
function walk(data, path, result, key) {
    var fn;

    switch (type(path)) {
      case 'string':
        fn = seekSingle;
        break;

      case 'array':
        fn = seekArray;
        break;

      case 'object':
        fn = seekObject;
        break;
    }

    if (fn) {
      fn(data, path, result, key);
    }
  }
1192255
def should_show_by_depth(self, cur_level=None):
        
        if cur_level is None:
            cur_level = self.cur_depth_level

        return (self.task_tree_depth < 0 or self.task_tree_depth >= cur_level)
643763
def depth(self):
        
        return len(self.path.rstrip(os.sep).split(os.sep))