Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

balancing paranthesis python

o=['[','{','(']
c=[']','}',')']

def check(s):
    a=[]
    for i in s:
       
        if i in o:
             a.append(i)
        elif i in c:
            pos=c.index(i)
            if((len(a)>0)and(o[pos]==a[len(a)-1])):
                a.pop()
            else:
                return "Unbalaced"
    if len(a)==0:
        return "bal"
    else:
        return "Unbal"
            

s='{{[])}}'
string=check(s)
print(string)
Comment

balancing paranthesis python

o=['[','{','(']
c=[']','}',')']

def check(s):
    a=[]
    for i in s:
       
        if i in o:
             a.append(i)
        elif i in c:
            pos=c.index(i)
            if((len(a)>0)and(o[pos]==a[len(a)-1])):
                a.pop()
            else:
                return "Unbalaced"
    if len(a)==0:
        return "bal"
    else:
        return "Unbal"
            

s='{{[])}}'
string=check(s)
print(string)
Comment

PREVIOUS NEXT
Code Example
Python :: converting tuple into string 
Python :: String search from multiple files 
Python :: Python Tkinter PanedWindow Widget 
Python :: how to take out every even number from a list in python 
Python :: What does if __name_=="_main__": do? 
Python :: python loop backwards 
Python :: django model example 
Python :: how to use assert in python 
Python :: matplot lib 3d plot autoscale 
Python :: generate n different colors matplotlib 
Python :: draw bounding box matplotlib 
Python :: python convert ascii to char 
Python :: install ansible with pip 
Python :: installing python3.9 on linux mint 20 
Python :: python round 1 decimal place 
Python :: eval function in python 
Python :: reportlab python add font style 
Python :: liste compréhension python 
Python :: python string continue next line 
Python :: python working with files and dirs 
Python :: python array join 
Python :: copy dataframe columns names 
Python :: current working directory in python 
Python :: how to use django-rest-framework-datatables 
Python :: how to write a comment in python 
Python :: Install discord.ui on windows 
Python :: numpy find mean of array 
Python :: check if string match regex python 
Python :: has no attribute python 
Python :: python get text of QLineEdit 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =