Skip to content

Group Anagrams#26

Open
Exzrgs wants to merge 1 commit intomainfrom
arai60-group-anagrams
Open

Group Anagrams#26
Exzrgs wants to merge 1 commit intomainfrom
arai60-group-anagrams

Conversation

@Exzrgs
Copy link
Copy Markdown
Owner

@Exzrgs Exzrgs commented May 31, 2024

問題:https://leetcode.com/problems/group-anagrams/description

https://github.com/fhiyo/leetcode/pull/15/files
これ、groupbyとか使った新しい書き方をしていて参考

Copy link
Copy Markdown

@hayashi-ay hayashi-ay left a comment

Choose a reason for hiding this comment

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

step2と同じコードでも良いのでstep3も提出して貰えると良いと思います。


5m

sorted(s)で返るのはlistじゃないことに注意
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ドキュメントにも目を通すと良いと思います。

Return a new sorted list from the items in iterable.

https://docs.python.org/3/library/functions.html#sorted

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.

ありがとうございます。
目を通しておきます👀

5m

sorted(s)で返るのはlistじゃないことに注意
.values()で返るのもlistじゃなくてdict_valuesという定義されたオブジェクト?
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ドキュメントにも目を通すと良いと思います。

Return a new view of the dictionary’s values.

https://docs.python.org/3/library/stdtypes.html#dict.values

from collections import defaultdict
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
sorted_str_to_strs = defaultdict(list)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

なんか変数名が微妙な気がします。うーん、sorted_str_to_originalとかはどうでしょうか?

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.

これ微妙ですよね~
ただ、個人的にはsorted_str_to_originalもあまりピンとこないんですよね... (私がoriginalに意味を見出しすぎているのかもしれないです)
sorted_str_to_anagramsだとどうなんでしょう?

Copy link
Copy Markdown

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 May 31, 2024

レビューしていただいてありがとうございます!

step2と同じコードでも良いのでstep3も提出して貰えると良いと思います。

こちら、理由をお伺いしてもよろしいでしょうか?

@hayashi-ay
Copy link
Copy Markdown

step2と同じコードでも良いのでstep3も提出して貰えると良いと思います。
こちら、理由をお伺いしてもよろしいでしょうか?

いやあ、そんな深い理由はないですが、step3をやっていないのか、step3をやった上でstep2と同じコードになったのかというのが気になるくらいですかね。

@Exzrgs
Copy link
Copy Markdown
Owner Author

Exzrgs commented May 31, 2024

なるほど~
step3.pyがない場合は、step3をやっていないと解釈していただいてよいです。
step3.pyがある場合は、step3をやった結果同じコードになったということですね。

今回は5mで解けちゃったのでstep3を省略しました。

@hayashi-ay
Copy link
Copy Markdown

個人的には最初の方はstep3を省略しないほうが良いとは思うのですが、お任せします。個人的な体験談としてはstep3はやっておいた方が良いかなと思いますが。

https://hayapenguin.com/notes/Posts/2024/04/24/how-to-practice-coding-effectively

練習の3ステップ目がすごい役立っていると思っていて、何回も間違える箇所というのはそもそも素直に処理が書けていなかったりして3回連続で通すように書き直すことでコードが整理されますし選択肢の好みも固まっていったように思えます。

ああ、そうそう。まさにこれなんですけど、不思議とみんなやりたがらないし、いかに効果的か伝わらないんですよねー。

だいたい、AC が出ると嬉しくなっちゃいます。

@oda
Copy link
Copy Markdown

oda commented May 31, 2024

まあ、私もこんな勝手なこと言ってましたね。
https://discord.com/channels/1084280443945353267/1230079550923341835/1238783345039638549

@Exzrgs
Copy link
Copy Markdown
Owner Author

Exzrgs commented Jun 3, 2024

step3が特に重要なのは感じていつつ、まだ若干軽視していた節があるかもしれないです。
欠かさずやっていこうと思います!

@Exzrgs
Copy link
Copy Markdown
Owner Author

Exzrgs commented Jun 4, 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.

3 participants