BBracketMast
Product

Product features · Bracket nesting depth

01

Accept the empty string with depth zero, but reject crossed pairs, unmatched brackets and every other character, including spaces.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Bracket nesting depth

● ● ●BracketMast●
A concrete starting point · Bracket nesting depth ×
def bracket_depth(text):
    if type(text) is not str:
        raise ValueError("bracket.type")
    stack, peak = [], 0
    pairs = {')': '(', ']': '[', '}': '{'}
    for char in text:
        if char in "([{":
            stack.append(char)
            peak = max(peak, len(stack))
        elif char in pairs:
            if not stack or stack.pop() != pairs[char]:
                raise ValueError("bracket.order")
        else:
            raise ValueError("bracket.alphabet")
    if stack:
        raise ValueError("bracket.unclosed")
    return peak
✳Bracket nesting depth
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗