code: def reduce_hierarchy(x, depth):
      
      _x = x.split('|')
      depth = len(_x) + depth - 1 if depth < 0 else depth
      return '|'.join(_x[0:(depth + 1)])
docs: Reduce the hierarchy (depth by `|`) string to the specified level