Skip to content

Add 929. Unique Email Addresses#14

Open
t0hsumi wants to merge 2 commits intomainfrom
929
Open

Add 929. Unique Email Addresses#14
t0hsumi wants to merge 2 commits intomainfrom
929

Conversation

@t0hsumi
Copy link
Copy Markdown
Owner

@t0hsumi t0hsumi commented Jan 25, 2025


class Solution:
def numUniqueEmails(self, emails: List[str]) -> int:
def validate(email: str) -> bool:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

validかどうかを判定しboolを返す関数なのでis_validという関数名がわかりやすいと思いました

https://zenn.dev/student_blog/articles/804a623a72742f#%E7%AC%AC%EF%BC%93%E7%AB%A0%E3%80%8C%E8%AA%A4%E8%A7%A3%E3%81%95%E3%82%8C%E3%81%AA%E3%81%84%E5%90%8D%E5%89%8D%E3%80%8D

if not domain.removesuffix('.com'):
return False
return True
def normalize(email: str) -> str:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

比較のために正規化しているため canonicalize のほうが良いと思います。内部的な冗長さの削減のために正規化するのを normalize と呼ぶようです。

Comment on lines +155 to +157
unique_emails = set()
for email in emails:
unique_emails.add(normalize(email))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

内包表記も可能ですがループを回す方が見やすいかもしれませんね。

unique_emails = {normalize(email) for email in emails}

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