+ 1
[SOLVED] Can anyone tell me the code for python data structure project4 balanced paranthese please.
4 Answers
+ 5
Mention not
+ 5
See I made some changes in ur code now:
https://code.sololearn.com/cR59S8HdeZHo/?ref=app
+ 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))
+ 1
Thank u so much it workedđ