Write a Logic to Validate only this partten (()), ((), )(

 

Code Example


#Write a Logic to Validate only this partten  (()), ((), )(

 

user_input = input("enter here :")
stack = [i for i in user_input]

for j,i in enumerate(user_input):
    if i == ')':
        if stack.index(')') > stack.index('('):
            stack.remove('(')
            stack.remove(')')

if ')' in stack or '(' in stack:
    print("no")
else:
    print("yes")

 

 

Comments

Popular posts from this blog

How To Create .ENV File in Python

Create a Large file for Test Data Processing using Python

How to solve the Liner Equation using Python