Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_matched(expression):
- stack = []
- dicty = {'(':')'}
- for x in expression:
- if dicty.get(x):
- stack.append(dicty[x])
- else:
- if len(stack) == 0 or x != stack[len(stack)-1]:
- return False
- stack.pop()
- return len(stack) == 0
- while True:
- a = is_matched(input())
- if a == 0:
- print("false")
- else:
- print("true")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement