part1 = "{ [ ( ) ] }"
part2 = "{ [ ( ] ) }"

parts = [part1, part2]

for part in parts:
    stack = []
    pairs = {')': '(', '}': '{', ']': '['}
    is_valid = True

    for char in part:
        if char in "({[":
            stack.append(char)
        elif char in ")}]":
            if not stack or stack[-1] != pairs[char]:
                is_valid = False
                break
            stack.pop()

    if stack:
        is_valid = False

    print(is_valid)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: