Conversation
競技プロ就活部PR用/6. Zigzag Conversion.md
Outdated
競技プロ就活部PR用/6. Zigzag Conversion.md
Outdated
競技プロ就活部PR用/6. Zigzag Conversion.md
Outdated
There was a problem hiding this comment.
そうですね、文字列の追記の再構築の話がなければ、Step1が自分も見やすいです。
ありがとうございます。
There was a problem hiding this comment.
odaさん、ありがとうございます。nodchipさんの意見も踏まえ、
最後の出力の部分はさまざまな書き方があり、step毎に色々試しましたが、別の変数作ってjoinして結合していくのが一番素直かつ見やすそうですね。
競技プロ就活部PR用/6. Zigzag Conversion.md
Outdated
There was a problem hiding this comment.
リストの内包表記を入れ子にすると、読んでいて認知負荷が高くなるため、避けたほうが良いと思います。 step1 のほうが分かりやすいように思いました。
There was a problem hiding this comment.
ありがとうございます。こちら、他参加者のコメントにあったため、試しに書いてみましたが、Step3の意義としては不適切だったかと思います。自分も、書いててかなりややこしく感じたため、よかったです。
基本的に選択肢として、Step1, 文字列の追記における再構築が問題となった場合をStep2を頭に入れておきます。
競技プロ就活部PR用/6. Zigzag Conversion.md
Outdated
There was a problem hiding this comment.
読みやすさとはまた別の話ですが、リストを作らなくてもgenerator expressionの形にすれば十分だと思いました。
https://peps.python.org/pep-0289/
For instance, the following summation code will build a full list of squares in memory, iterate over those values, and, when the reference is no longer needed, delete the list:
sum([x*x for x in range(10)])Memory is conserved by using a generator expression instead:
sum(x*x for x in range(10))
There was a problem hiding this comment.
ありがとうございます。みやすさ以外でも視点を広げるためにコメントいただけるのはありがたいです。
たしかに、下記の書き方でも十分ですね。
return "".join(l for row in ordered_letters for l in row)
競技プロ就活部PR用/6. Zigzag Conversion.md
Outdated
There was a problem hiding this comment.
問題で与えられた文字列をzigzagにして行ごとに読んだときの文字列を返したいので、ordered_lettersという変数名は読み手を混乱させるかもなと思いました。2次元のリストであることも名前からは分かりにくそうです。
rowsとかzigzag_rowsで良い気がしました
There was a problem hiding this comment.
ありがとうございます、参考になります。2次元リストをrowsにして、各行を取り出す際にrowにすると確かに伝わりやすいですね。nodchipさんからのコメントも合わせて、zigzag_rowsにします。
競技プロ就活部PR用/6. Zigzag Conversion.md
Outdated
There was a problem hiding this comment.
ありがとうございます。意識しておりませんでした。以後 str.join(iterable)にします。
参照: https://docs.python.org/3/library/stdtypes.html
https://leetcode.com/problems/zigzag-conversion/description/