Skip to content

Zigzag Conversion#3

Merged
Exzrgs merged 5 commits intomainfrom
arai60-zigzag-conversion
May 15, 2024
Merged

Zigzag Conversion#3
Exzrgs merged 5 commits intomainfrom
arai60-zigzag-conversion

Conversation

@Exzrgs
Copy link
Copy Markdown
Owner

@Exzrgs Exzrgs commented Apr 28, 2024


rows = [[] for _ in range(numRows)]
current = 0
adding = -1
Copy link
Copy Markdown
Owner Author

@Exzrgs Exzrgs Apr 28, 2024

Choose a reason for hiding this comment

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

step2ではaddingstepに変更していますが、addingでも悪くはないと思っています。
どうでしょうか。
感覚のすり合わせを行いたいです!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

addingは日本語で言うところどんなつもりで書きましたか?

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.

「足すもの」くらいの感覚ですね。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ちょっとaddingという名前から中に何が入っているか分からない気がしました。ここでもstepとなってるので、stepの方がいいかと思います。
https://docs.python.org/3/library/stdtypes.html#range

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.

承知しました。
ありがとうございます!

@Exzrgs
Copy link
Copy Markdown
Owner Author

Exzrgs commented Apr 28, 2024

(ちなみにですが、一度解いたことがあります)

for i in range(numRows):
merged_rows.extend(rows[i])
zigzag = "".join(merged_rows)
return zigzag
Copy link
Copy Markdown

@liquo-rice liquo-rice Apr 28, 2024

Choose a reason for hiding this comment

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

return "".join(c for c in row for row in rows)でどうですか?上の書き方だと、コピーがあります。(forループの順番は間違っているかもしれないです…)

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.

コピーというと

for i in range(numRows):
    merged_rows.extend(rows[i])

の部分ですかね?

提案していただいたコードだと個人的には可読性が下がる気がしており、できれば別の方式を採用したい感覚です。

Copy link
Copy Markdown

@liquo-rice liquo-rice Apr 28, 2024

Choose a reason for hiding this comment

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

はい、rowsから文字(列)がmerged_rowsにコピーされているので、無駄な処理になっているかと。

こちらが正しかったです。"".join(char for row in rows for char in row)。これ見てすぐ意味分かると思ったのですが、そうでもないですか?

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.

ありがとうございます。
自分がその記法に慣れていないだけな気がしてきたので、今後使って慣れていこうと思います!


rows = [[] for _ in range(numRows)]
current = 0
adding = -1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

addingは日本語で言うところどんなつもりで書きましたか?

@Exzrgs Exzrgs merged commit 0303324 into main May 15, 2024
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.

2 participants