Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_braces_sequence_correct(expression):
- stack = []
- for symbol in expression:
- if symbol in '([{':
- stack.append(symbol)
- elif symbol in ')]}':
- if len(stack) == 0:
- return False
- x = stack.pop()
- if not (x == '(' and symbol == ')'or
- x == '[' and symbol == ']'or
- x == '{' and symbol == '}'):
- return False
- return len(stack) == 0
- print(is_braces_sequence_correct(input()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement