Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1.  
  2. def is_matched(expression):
  3. stack = []
  4. dicty = {'(':')'}
  5. for x in expression:
  6. if dicty.get(x):
  7. stack.append(dicty[x])
  8. else:
  9. if len(stack) == 0 or x != stack[len(stack)-1]:
  10. return False
  11. stack.pop()
  12. return len(stack) == 0
  13.  
  14. while True:
  15. a = is_matched(input())
  16. if a == 0:
  17. print("false")
  18. else:
  19. print("true")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement