Skip to content

127. Word Ladder#18

Open
tom4649 wants to merge 1 commit intomainfrom
127.Word-Ladder
Open

127. Word Ladder#18
tom4649 wants to merge 1 commit intomainfrom
127.Word-Ladder

Conversation

@tom4649
Copy link
Copy Markdown
Owner

@tom4649 tom4649 commented Mar 15, 2026

word_set.discard(beginWord)

begin_frontier = {beginWord}
end_frontier = {endWord}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

細かいですが、snake_caseとlowerCamelCaseが入り混じった変数名には意図があるのか気になりました。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

引数がCamel Caseで自分が使っているのがsnake_caseなのでこうなってしまいました。
これを気持ち悪いと思う感覚は大事ですね

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

本当は LeetCode のシグネイチャーが標準的な記法に従っていないのですが、Python の場合は、keyword 呼び出しがあるので、シグネイチャーを変えると意味が変わる可能性がありますね。

https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.wqduubixdpe4

Copy link
Copy Markdown
Owner Author

@tom4649 tom4649 Mar 16, 2026

Choose a reason for hiding this comment

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

https://docs.python.org/3/tutorial/controlflow.html#special-parameters
pos_only, /, standard, *, kwd_only と書くこと、知らなかったです。勉強になりました。

from collections import defaultdict


class NeighborWords:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

クラスが機能するために必要な情報はコンストラクタ(あるいはbuilderなど)で与えられるべきです。from_wordsを最初に絶対に使わないと使い間違えるクラスになっていませんか?
また、from_wordsは何度でも呼び出せる必要があるものでしょうか?そうでないならばクラス生成後はこのメソッドを叩けないのが望ましいです

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

classmethodなどは使わずに def init(self, words): とするべきですね。ご指摘のとおりだと思います。

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