TheAlgorithms / Python Public
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
Add all_construct dynamic programming implementation #5626
Conversation
Click here to look at the relevant links ⬇️
🔗 Relevant LinksRepository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
Click here to look at the relevant links ⬇️
🔗 Relevant LinksRepository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
dynamic_programming/all_construct.py
Outdated
|
||
if word_bank is None: | ||
word_bank = [] |
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.
Safer in the presence of other falsey values...
if word_bank is None: | |
word_bank = [] | |
word_bank = word_bank or [] |
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.
Ok this is cleaner. Will update.
dynamic_programming/all_construct.py
Outdated
""" | ||
|
||
|
||
def all_construct(target: str, word_bank: list[str] = None) -> list[list[str]]: |
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.
list[str] = None
makes no sense because None is not a list.
def all_construct(target: str, word_bank: list[str] = None) -> list[list[str]]: | |
def all_construct(target: str, word_bank: list[str] | None = None) -> list[list[str]]: |
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.
I followed the article you mentioned previously regarding mutable default arguments
(https://docs.python-guide.org/writing/gotchas/)
and I don't see a problem in defining a default argument as None and later changing it to an empty list in the code.
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.
Ohh I think I see.
do you mean the type hint is not clear that way?
mypy not happy... Can you run it on your machine?
|
I think it's a problem with a type hint I defined for 'table' . Testing it. |
Fixed.. |
Build is getting errors on some other files . Could you check it please? @cclauss |
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.The text was updated successfully, but these errors were encountered: