Skip to content

Lists moved outside the function#4

Open
mareenanazir wants to merge 4 commits intomasterfrom
new-branch
Open

Lists moved outside the function#4
mareenanazir wants to merge 4 commits intomasterfrom
new-branch

Conversation

@mareenanazir
Copy link
Owner

No description provided.

@mareenanazir mareenanazir requested a review from marslan02 July 16, 2019 13:49
Copy link
Collaborator

@marslan02 marslan02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for the use of stack logic.
Your logic is good I mostly added language related comments.
Also repos are public so its better to add all of this code in a proper repository instead of hello-world and file names are also important.

class.py Outdated
closing_parantheses_list=[')','}',']']

def __init__(self,expression):
self.expression=expression
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need expression at class level this way we can't easily use same instance of class for multiple validations.

class.py Outdated
self.expression=expression
self.parantheses_stack=[]

def check_balance(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think of a more descriptive name.

class.py Outdated
@@ -0,0 +1,35 @@
class ValidatorClass:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need class keyword in a class name.

class.py Outdated
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.parantheses_stack.pop() also returns the value, think a solution with this, it will simplify you code even more

class.py Outdated
return False
else:
return False
if len(self.parantheses_stack)==0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(self.parantheses_stack)==0 is a boolean expression we can simply return this and save the cost of this check.

class.py Outdated
expression_two="(){}"
validator_object_one=ValidatorClass(expression_one)
validator_object_two=ValidatorClass(expression_two)
#flag=validator_object_one.check_balance()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to remove unused code before committing final changes

class.py Outdated
def main():
expression_one="(){}}"
expression_two="(){}"
validator_object_one=ValidatorClass(expression_one)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use single instance of a class for multiple validations. see comment above for reference.

class.py Outdated
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()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an old way of formatting use format() or f strings for it

Mareena.Nazir and others added 2 commits July 17, 2019 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants