Program to Check Redundant Parenthesis in Python || Python
In this we are going to see a basic program to check redundant parenthesis in Python Programming Language.



# The string should have balanced brackets

s = "(a+(c+b))"
l = []
o = ['+', '-', '*', '/']
red = False

for i in s:
    if i == '(' or i in o:
        l.append(i)
    elif i == ')':
        if l[-1] == '(':
            red = True
        while l[-1] in o:
            l.pop()
        l.pop()

if red==False:
    print("There are no redundant brackets!")
else:
    print("There are redundant brackets!")

# Coded by Saahil


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post