Advertisement
Risonna

is braces sequence correct

Aug 1st, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. def is_braces_sequence_correct(expression):
  2.     stack = []
  3.     for symbol in expression:
  4.         if symbol in '([{':
  5.             stack.append(symbol)
  6.         elif symbol in ')]}':
  7.             if len(stack) == 0:
  8.                 return False
  9.             x = stack.pop()
  10.             if not (x == '(' and symbol == ')'or
  11.                     x == '[' and symbol == ']'or
  12.                     x == '{' and symbol == '}'):
  13.                 return False
  14.     return len(stack) == 0
  15.  
  16. print(is_braces_sequence_correct(input()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement