Skip to content

Conversation

Satorien
Copy link
Owner

@Satorien Satorien commented Aug 7, 2025

class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
string_length = len(s)
breakableTo = [True] + [False] * string_length

Choose a reason for hiding this comment

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

変数名は snake case にするのが一般的だと思います。
https://peps.python.org/pep-0008/#function-and-variable-names
breakableTo のTo については意味を読み取ることができませんでした。
また、string_length は変数にするほど重要でない、len(s) より情報量が増えていない気がしました。

Copy link
Owner Author

@Satorien Satorien Aug 10, 2025

Choose a reason for hiding this comment

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

breakableTo[i]とすれば英文的には分かりやすいのかなと思っていました
また、string_lengthについては二回呼び出すので保持しても良いのかなと思いましたが確かにない方が良いですかね

Choose a reason for hiding this comment

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

ただの一意見ですが、自分もlen(s)をそのまま使ってしまって良いと思いました。
理由としては、len(s)はそもそも可読性が高い。string_lengthの変数名が少し長い。ためです。

if start in triedFrom:
continue
triedFrom.add(start)
for i in word_lengths:

Choose a reason for hiding this comment

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

i より word_length の方が読みやすいと思いました。初め word_lengths の役割がわからなかったので、word_length_to_words = {文字数: list[単語]} のようにするとわかりやすくなるかもしれません。もしくはコメントで補足するのもありでしょうか。

Copy link
Owner Author

Choose a reason for hiding this comment

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

確かにそれありですね。ありがとうございます!

@Mike0121
Copy link

全体的に、もう少し改行があると読みやすいかな?と思いました。好みかもしれませんし、無駄に改行が多いよりは良いと思います。

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