def check text stack for in text if or or stack append if or or and no

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def check(text):
stack = []
for i in text:
if (i == '(' or i == '[' or i == '{'):
stack.append(i)
if ((i == ')' or i == ']' or i == '}' ) and ( not stack or abs(ord(i) - ord(stack.pop())) > 2 ) ):
return False
return not stack
text = open('text.txt').read()
print check(text)