Пример #1
0
def is_balanced_parentheses(string: str):
    stack = Stack()
    for char in string:
        if char == "(":
            stack.push("(")
        elif char == ")":
            if stack.isempty():
                return False
            else:
                stack.pop()

    if stack.isempty():
        return True
    else:
        return False
Пример #2
0
def is_balanced_symbols(string: str):
    stack = Stack()
    for char in string:
        if char in "([{":
            stack.push(char)
        elif char in "}])":
            if stack.isempty():
                return False
            elif match(stack.peek(), char):
                stack.pop()
            else:
                return False
    if stack.isempty():
        return True
    else:
        return False