+ 1

[SOLVED] Can anyone tell me the code for python data structure project4 balanced paranthese please.

21st Apr 2021, 2:57 PM
Vaibhav Adhav
Vaibhav Adhav - avatar
4 Antworten
+ 5
Mention not
21st Apr 2021, 3:29 PM
Kǟrɨsɦmǟ ❥
Kǟrɨsɦmǟ ❥ - avatar
+ 5
See I made some changes in ur code now: https://code.sololearn.com/cR59S8HdeZHo/?ref=app
21st Apr 2021, 3:27 PM
Kǟrɨsɦmǟ ❥
Kǟrɨsɦmǟ ❥ - avatar
+ 2
def arepairs(open,close): if open =="(" and close ==")": return "true" if open =="[" and close =="]": return "true" if open =="{" and close =="}": return "true" else: return "false" def balanced(A): stack=[] for i in range(len(A)): if A[i]=="(" or A[i]=="[" or A[i]=="{": stack.append(A[i]) elif A[i]==")" or A[i]=="]" or A[i]=="}": if arepairs(stack[-1],A[i]): stack.pop() else: return "false" if len(stack)==0: return "true" else: return "false" print (balanced(A))
21st Apr 2021, 3:10 PM
Vaibhav Adhav
Vaibhav Adhav - avatar
+ 1
Thank u so much it worked😊
21st Apr 2021, 3:29 PM
Vaibhav Adhav
Vaibhav Adhav - avatar