Загрузка данных


def check_text(text):
    stack = []
    pairs = {')': '(', ']': '[', '}': '{', '»': '«'}
    quotes = '"'

    for ch in text:
        if ch in '([{«':
            stack.append(ch)
        elif ch in ')]}»':
            if not stack or stack[-1] != pairs[ch]:
                return False
            stack.pop()
        elif ch == quotes:
            if stack and stack[-1] == quotes:
                stack.pop()
            else:
                stack.append(quotes)

    return len(stack) == 0


print(check_text('Он сказал: «(Это [пример])»'))
print(check_text('Он сказал: «Привет!'))