Skip to content

Add files via upload #101

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

Merged
merged 1 commit into from
Apr 3, 2024
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
28 changes: 28 additions & 0 deletions Week05/emails_ali_duman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import re

class Emails(list):
def __init__(self, emails):
validated_emails = self.validate(emails)
self.data = validated_emails
super().__init__(validated_emails)

@staticmethod
def validate(emails):
unique_emails = []
email_regex = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"

for email in emails:
if not isinstance(email, str):
raise ValueError("All items must be strings.")
if not re.match(email_regex, email):
raise ValueError(f"Invalid email address: {email}")
if email not in unique_emails:
unique_emails.append(email)

return unique_emails

def __repr__(self):
return f"{self.__class__.__name__}({self.data})"

def __str__(self):
return f"{self.data}"
Loading