Conversation
| if numRows == 1 or numRows >= len(s): | ||
| return s | ||
|
|
||
| row_i = 0 |
There was a problem hiding this comment.
個人的にはrow_iと省略せずにrow_indexとしたほうがわかりやすい気がします。
より名前の長いdirectionと同じぐらい(というより、組になって)重要な変数だからだと思います。
|
|
||
| for i in range(numRows): | ||
| zigzag_rows[i] = ''.join(zigzag_rows[i]) | ||
| flattened_rows = ''.join(zigzag_rows) |
There was a problem hiding this comment.
itertools.chain.from_iterable(zigzag_rows)
としたり、わかりにくいですが
[s for row in zigzag_rows for s in row]
という書き方もあるみたいです。
https://docs.python.org/3/library/itertools.html#itertools.chain
https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions
There was a problem hiding this comment.
そうですね。Generator comprehension は nest することができます。二重に内包表記を書けるということです。
[] はリストが作られますが、() にしておくと、List comprehension ではなくてジェネレーターになります。
"".join(c for row_chars in rows for c in row_chars)
https://discord.com/channels/1084280443945353267/1322513618217996338/1361352231668158564
| * 解答時間 | ||
| - 1回目: 3:47 | ||
| - 2回目: 3:55 | ||
| - 3回目: 5:07 |
There was a problem hiding this comment.
余談ですが、恐らく直近で問題問わずレビュー依頼を出していた5人にdiscordでメンションをしている気がするのですが、直近で同じ問題(今回であれば6. zigzag conversion)を解いた方にメンションを送っているのが多数派だと思います。(やったことない問題のレビューも面白いので、自分は大丈夫ですが)
自分はdiscordの検索欄で「in: レビュー依頼 6. zigzag」などと検索して探しています。
There was a problem hiding this comment.
ありがとうございます。いつも誰に出そうか迷っていたので、そういった情報はとても助かります。
| row_i += direction | ||
|
|
||
| for i in range(numRows): | ||
| zigzag_rows[i] = ''.join(zigzag_rows[i]) |
There was a problem hiding this comment.
zigzag_rowsがlist[list[str]]からlist[str]になるのは驚きました。避けたほうが無難かと思います
6. Zigzag Conversion
次回予告: 8. String to Integer (atoi)