def obtain_answer()

in arctic_inference/dynasor/entropy.py [0:0]


def obtain_answer(s: str) -> str:
    """Extract the first complete answer from a string by matching braces.
    
    Args:
        s: Input string containing potential answer
        
    Returns:
        str: The first complete answer found, or empty string if none found
    """
    # Find first unpaired } by counting { and }
    stack = []
    for i, c in enumerate(s):
        if c == "{":
            stack.append(c)
        elif c == "}":
            if not stack:  # No matching { found
                return s[:i]
            stack.pop()
    return ""