Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Week05/emails_melda_gungor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Emails(list):
def __init__(self, emails=None):
if emails is None:
emails = []

valid_unique_emails = []
for email in emails:
self.validate(email)
if email not in valid_unique_emails:
valid_unique_emails.append(email)


super().__init__(valid_unique_emails)
self.data = self

@staticmethod
def validate(email):
if not isinstance(email, str):
raise ValueError(f"email must be a string, got {type(email)}")
if email.count("@") != 1:
raise ValueError(f"invalid email address: {email}")

user, domain = email.split("@")

if not user or not domain:
raise ValueError(f"invalid email address: {email}")

if "." not in domain or domain.startswith(".") or domain.endswith("."):
raise ValueError(f"invalid email address: {email}")

return True

def __repr__(self):
return f"Emails({list(self)})"

def __str__(self):
return super().__str__()

Loading