Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions paranthesis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openingParanthesisList=['(','{','[']
closingParanthesisList=[')','}',']']
def checkBalance(expression):
openingParanthesisList=['(','{','[']
closingParanthesisList=[')','}',']']
stack=[]
for char in expression:
if char in openingParanthesisList:
Expand Down
30 changes: 30 additions & 0 deletions validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Validator:
parantheses_dict={
'(':')',
'{':'}',
'[':']'
}

def check_parantheses_balance(self,expression):
parantheses_stack=[]
for char in expression:
if char in self.parantheses_dict.keys():
parantheses_stack.append(char)
elif char in self.parantheses_dict.values():
if len(parantheses_stack)!=0:
popped_parentheses=parantheses_stack.pop()
if self.parantheses_dict[popped_parentheses]!=char:
return False
else:
return False
return len(parantheses_stack)==0

def main():
expression_one="(){}}"
expression_two="(){}"
validator_object=Validator()
print("{} : {}".format(expression_one,validator_object.check_parantheses_balance(expression_one)))
print("{} : {}".format(expression_two,validator_object.check_parantheses_balance(expression_two)))

if __name__=='__main__':
main()