Skip to content

Refactor code to uphold DRY principle. #169

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Refactor code to uphold DRY principle. #169

wants to merge 1 commit into from

Conversation

nnamdiib
Copy link
Contributor

The numerous "K.replace()" lines at the bottom can be refactored using a list of tuples.
A simple loop can then do all the replacing necessary.
And if you want to add more characters to replace, just update the list as required.

The numerous "K.replace()" lines at the bottom can be refactored using a list of tuples.
A simple loop can then do all the replacing necessary.
And if you want to add more characters to replace, just update the list as required.
@UncleAnson
Copy link
Contributor

Don't Repeat Yourself Principle

replace_list = [(' ', ''), ('^', '**'), ('=', ''), ('?', ''), ('%', '/100')]

for tup in replace_list:
k = k.replace(tup[0], tup[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

for old, new in replace_list:
    k = k.replace(old, new)

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.

3 participants