-
Notifications
You must be signed in to change notification settings - Fork 0
Lists moved outside the function #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| class ValidatorClass: | ||
| opening_parantheses_list=['(','{','['] | ||
| closing_parantheses_list=[')','}',']'] | ||
|
|
||
| def __init__(self,expression): | ||
| self.expression=expression | ||
|
||
| self.parantheses_stack=[] | ||
|
|
||
| def check_balance(self): | ||
|
||
| for char in self.expression: | ||
| if char in self.opening_parantheses_list: | ||
| self.parantheses_stack.append(char) | ||
| elif char in self.closing_parantheses_list: | ||
| index=self.closing_parantheses_list.index(char) | ||
|
||
| if len(self.parantheses_stack)!=0: | ||
| if self.opening_parantheses_list[index]==self.parantheses_stack[len(self.parantheses_stack)-1]: | ||
| self.parantheses_stack.pop() | ||
| else: | ||
| return False | ||
| else: | ||
| return False | ||
| if len(self.parantheses_stack)==0: | ||
|
||
| return True | ||
|
|
||
| def main(): | ||
| expression_one="(){}}" | ||
| expression_two="(){}" | ||
| validator_object_one=ValidatorClass(expression_one) | ||
|
||
| validator_object_two=ValidatorClass(expression_two) | ||
| #flag=validator_object_one.check_balance() | ||
|
||
| print("%s : %r" % (expression_one,validator_object_one.check_balance())) | ||
| print("%s : %r" % (expression_two,validator_object_two.check_balance())) | ||
|
||
|
|
||
| if __name__=='__main__': | ||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need
classkeyword in a class name.