-
Notifications
You must be signed in to change notification settings - Fork 0
929. Unique Email Addresses #16
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
base: main
Are you sure you want to change the base?
Conversation
| def normalize(email: str) -> str: | ||
| is_local_part = True | ||
| is_ignore_part = False | ||
| elements_of_normalization = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
他の単語がシンプルな分、elements_of_normalization という名前に違和感がありました。(長いな、何が入っているのかパッと分からなかったな)normalized_chars のような単語もありなのかなと思いました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有難うございます!
確かに他の変数名とのバランスも考えた方がいいかもしれませんね。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
英語としても不自然に聞こえます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有難うございます。
あまり感覚がないので矯正していきたいです。
| is_local_part = True | ||
| is_ignore_part = False | ||
| elements_of_normalization = [] | ||
| for char in email: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
予約語になり得る単語を変数名として使うのはよろしくないというコメントを、どこかで見た気がします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一応pythonでの予約語にはなっていない筈ですが、紛らわしいかもしれませんね。
| normalized_local_part = local_part.split('+')[0] | ||
| normalized_local_part = normalized_local_part.replace('.', '') | ||
|
|
||
| return f'{normalized_local_part}@{domain_part}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stringを作らないで、tupleで返してもよさそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確かに正規化されたメールアドレスを作る必要は必ずしもないですね。
有難うございます。
| local = email.split('@')[0] | ||
| domain = email.split('@')[1] | ||
| if local.find('+') > 0: | ||
| local = local[:local.find('+')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2回local.find('+')をしているのが気になります。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうですね。
1回インデックスを取得して使いまわせば良かったです。
| def normalize(email: str) -> str: | ||
| is_local_part = True | ||
| is_ignore_part = False | ||
| elements_of_normalization = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
英語としても不自然に聞こえます。
| def numUniqueEmails(self, emails: List[str]) -> int: | ||
| def normalize(email: str) -> str: | ||
| is_local_part = True | ||
| is_ignore_part = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_ignored_part
複数のループに分けた方が自然だと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fhiyoさんのコメントにもありましたね。
実装し直してみようと思います。
無駄なfindをしないように修正
パート毎に分けてループ処理する方式の実装を追加
| - https://www.ietf.org/rfc/rfc1034.txt#:~:text=The%20labels%20must%20follow%20the%20rules%20for%20ARPANET%20host%20names.%20%20They%20must%0Astart%20with%20a%20letter%2C%20end%20with%20a%20letter%20or%20digit%2C%20and%20have%20as%20interior%0Acharacters%20only%20letters%2C%20digits%2C%20and%20hyphen.%20%20There%20are%20also%20some%0Arestrictions%20on%20the%20length.%20%20Labels%20must%20be%2063%20characters%20or%20less | ||
| - RFC5322 | ||
| - https://datatracker.ietf.org/doc/html/rfc5322#:~:text=local-part%20%20%20%20%20%20%3D%20%20%20dot-atom%20/%20quoted-string%20/%20obs-local-part | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
エンジニアというのはこういうところを普段から読んでいるので、「普段だったらリファレンスマニュアルや RFC を確認する」という発言は好意的に受け取られます。
|
liquo-riceさん、goto-untrappedさん、odaさん、レビューをありがとうございました! |
| > プログラムが停止する。 | ||
| > エラーを示す値を返す。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TORUS0818
”プログラムが停止する”の選択肢の場合って、何を返す想定でしょうか??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
例えば
email = '"@"@.com'
local_name, domain_name = email.split('@')とかでValueError: too many values to unpack (expected 2)みたいな感じでしょうか。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log Fatal を想定しています。よい並列計算ミドルウェアがあったりするとこれがよいケースがあります。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ミスリードしてました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TORUS0818
ありがとうございます。
ValueError: too many values to unpack (expected 2)
これで落ちちゃうとログを見に来た人は想定された終了なのか、意図しない異常終了なのか分からなくて焦ると思うので、親切なlog残して落ちて上げたほうがいいのかなと思いました!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます!
ここら辺の感覚、経験不足であまりないので意識していきたいと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
現代のプログラム
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コードを書くときには、エンジニアリングをしてくださいと言っていますが、そもそもそのプログラムが何のために動いているかと、細かい動作をどうしたいかを接続することもそのエンジニアリングです。要は、大局観をもって行動して欲しいということです。それで、現代のプログラムは、人が起動して一つだけで動いている場合だけではないので、そうではない想定を考えてよしあしを決めてください。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます。
実は現在の職場では(暗に)その真逆を求められています。。
書いたコードは基本他人は読まないし、責任は自分で持つ、細かいことに拘っている時間があるならその分早く結果(なんらかの数値や動くもの、という意味です)を出したほうが価値がある、という感じです。
(もちろん、もし同じスピードで、そのような配慮がなされたコードが書けるのならその方が良い、というのは合意していただけるとは思うのですが)
元々、上記のような状況に課題を感じて意識的に修正しようとはしていたのですが、まだまだ見えていないものが多いと感じます。皆さんと積極的にコミニュケーションして、この練習会でしっかり身につけられるよう頑張ります!
| def numUniqueEmails(self, emails: List[str]) -> int: | ||
| unique_email_address = set() | ||
| for email in emails: | ||
| local_part, domain_part = email.rsplit('@', maxsplit=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constraints に "Each emails[i] contains exactly one '@' character." とあるので、第二引数は書かなくても良いかもしれません。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| local_part, domain_part = email.rsplit('@', maxsplit=1) | ||
| normalized_local_part = local_part.split('+')[0] | ||
| normalized_local_part = normalized_local_part.replace('.', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python の文字列型は immutable なので、normalized_local_part を作るのに3つ値が宣言されますね。これを1回で済むように改善してもいいかなと思いました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有難うございます。
具体的にはどのようにすれば良さそうでしょうか。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
他の方に同じコメントをしたら oda さんから返信がありました。ちゃんと見て後ほど返信しますが、仰られてる通りあまり適切でないレビューだった気がしています... すいません🙏
SuperHotDogCat/coding-interview#30 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有難うございます。
具体的にはどのようにすれば良さそうでしょうか。
上記 oda さんのコメントにもある通りおそらく遅くなってしまいますが... 以下のようにすればオブジェクトの生成数は減らせるかと思います
local_part, domain_part = email.rsplit('@', maxsplit=1)
normalized_local_part = []
for char in local_part:
if char == '+':
break
if char != '.':
normalized_local_part.append(char)
https://leetcode.com/problems/unique-email-addresses/description/