problem:python data structure-(Balanced parenthesis)..how can i fix my bug...? pls help me anyone.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

problem:python data structure-(Balanced parenthesis)..how can i fix my bug...? pls help me anyone..

def arePairs(open,close): if open=='[' and close==']': return True if open=='{' and close=='}': return True if open=='(' and close==')': return True 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] or len(stack)!=0): stack.pop() else: return False if len(stack)==0: return True else: return False A=input() print(Balanced(A)) please anyone fix my bug???

13th Mar 2021, 4:03 AM
Mahidul Islam
1 Answer
+ 3
You only need to do it for parenthesis. You can remove all the code for square brackets '[' ']' and curly braces '{' '}'.
13th Mar 2021, 4:45 AM
ChaoticDawg
ChaoticDawg - avatar