Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #to check wheather the given parenthesis are valid or not implementation is done using stack
- pat = '[({()})[]}'
- lst = []
- srt_pat = ['{', '(', '[']
- cls_pat = ['}', ')', ']']
- chec_lst=['{}','()','[]']
- for i in range(len(pat)):
- if (pat[i] in srt_pat):
- lst.append(pat[i])
- else:
- x=lst[-1]+pat[i]
- if (x in chec_lst):
- lst.pop()
- else:
- print('not valid pat')
- break
- print(lst)
- if (len(lst) == 0):
- print('valid pat')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement