Skip to content

Add 929. Unique Email Addresses #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add 929. Unique Email Addresses #14

wants to merge 2 commits into from

Conversation

t0hsumi
Copy link
Owner

@t0hsumi t0hsumi commented Jan 25, 2025


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

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

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

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