Skip to content
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

Refactoring string concatenations #2

Open
saikumarmk opened this issue Jan 7, 2023 · 0 comments
Open

Refactoring string concatenations #2

saikumarmk opened this issue Jan 7, 2023 · 0 comments
Assignees
Labels
refactor Code to be rewritten

Comments

@saikumarmk
Copy link
Contributor

In place of say:

output = ""
for unit in prereqs_list:
    output += f'{unit}\n'

It is much cleaner to construct a string in one go as the string concatenate operator creates a new string (strings are immutable by default). While operations such as these are inconsequential due to scale, it is good practice to do the following:

output = "\n".join(prereqs_list)

If you're iterating over a more complex structure and need to extract some terms, you can do it as follows:

output = ",".join([f"{data['blah']}: {data['foo']}" for data in bar])

Cutting down to one line. This also solves the asymmetry of requisites where you may get a result like "MTH1030, ENG1005," with a trailing comma. This can e found in the unit_embed.py file, on lines 35, 43, 47, and 50-54.

@saikumarmk saikumarmk added the refactor Code to be rewritten label Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code to be rewritten
Projects
None yet
Development

No branches or pull requests

2 participants