Skip to content

Create 383. Ransom Note.md#28

Open
Kitaken0107 wants to merge 2 commits intomainfrom
Kitaken0107-patch-30
Open

Create 383. Ransom Note.md#28
Kitaken0107 wants to merge 2 commits intomainfrom
Kitaken0107-patch-30

Conversation

@Kitaken0107
Copy link
Owner

```

# 2nd・3rd
count_charとするよりcount_magazineとした方が分かりやすそうだと思い変更
Copy link

@sakzk sakzk Jun 23, 2024

Choose a reason for hiding this comment

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

count_magazine だと、「辞書を数える」という述語、もしくは、count_of_magazine (辞書の数) の of が省略されたものとかなと予想してしまいそうです。
辞書の命名は、key と value の対応がわかりやすいように、<key>_to_<value> の形式で書いておられる方が多いように思います。
今回の問題だと、char_to_count とかでしょうか。

Copy link
Owner Author

Choose a reason for hiding this comment

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

命名例わかりやすいです。
ありがとうございます。

:type magazine: str
:rtype: bool
"""
count_char = defaultdict(int)
Copy link

Choose a reason for hiding this comment

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

すでに確認されているかもしれませんが、defaultdict() に関連しては、

  1. dict() をつかって書き直せるか https://discord.com/channels/1084280443945353267/1235971495696662578/1236912204209586266
  2. deafultdict() を実装できるか https://discord.com/channels/1084280443945353267/1226508154833993788/1243957056034308148
    の議論があります。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。
1に関しては解く際に選択肢の幅として思いついておりまして、
他でもやっているので今回は省略させていただきます。

2は考えてみたことがないので、議論を読んでみようと思います。

URLまで引っ張っていただきありがとうございます。

Copy link
Owner Author

Choose a reason for hiding this comment

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

defaultdictの実装を反映させていただきました。

Copy link

@colorbox colorbox left a comment

Choose a reason for hiding this comment

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

ざっとみましたがよさそうに思いました 👍

### ロジック
①magazineの文字をカウント
②ransomNoteの文字の数だけ上記から引き算
③もし既に文字のカウントから0のところを引こうとしていたら、return False、回り切ればTrue

Choose a reason for hiding this comment

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

ロジックはこれが正攻法だと思います

return False
count_magazine[char] -= 1
return True
```

Choose a reason for hiding this comment

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

良いと思います

@rihib rihib mentioned this pull request Sep 9, 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.

4 participants