Easy Stack

Check Brackets

1
2
3
4
5
6
7
8
9
10
11
12
def check_brackets(expression):
    stack = []
    brackets = {'(': ')', '{': '}', '[': ']'}

    for char in expression:
        if char in brackets.keys():  # Opening bracket
            stack.append(char)
        elif char in brackets.values():  # Closing bracket
            if not stack or brackets[stack.pop()] != char:
                return False

    return len(stack) == 0

🎰