Skip to content

Conversation

fhiyo
Copy link
Owner

@fhiyo fhiyo commented May 29, 2024

```python
from dataclasses import dataclass

@dataclass
Copy link

Choose a reason for hiding this comment

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

named tuple という手がありますよ。

Copy link

Choose a reason for hiding this comment

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

あ、named tuple には順序が入るという話です。

```python
class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
tally = Counter(nums)

Choose a reason for hiding this comment

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

(本質的な話ではないのですが)tally という単語を見たことがなかったので、少し戸惑いました。これは僕個人の英語力の問題かもしれないので、他の人はどうなのか気になります。

Copy link
Owner Author

Choose a reason for hiding this comment

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

Rubyのメソッドに Enumerable#tally というのがあって、それで自分は知って使っちゃいました。メソッド名として使われているこの語が変数名として使っても自然なのかは分からないです...

↑この辺見てみましたが、うーん何とも言えない感じでした

Choose a reason for hiding this comment

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

Rubyのメソッドに Enumerable#tally というのがあって、それで自分は知って使っちゃいました。

リンクの共有ありがとうございます。Ruby を触ったことがなく知らなかったので勉強になりました。このメソッドの処理を見ると、今回の用途に合っていそうなので問題なさそうです。

コメントしたからにはなにか良い代案を出そうと思いましたが、パッと出なかったです。(僕が過去に解いたものを見返しましたが freq_dict だとか freq と書いていてあんまりイケてなさそうでした。)

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