From 36a4f2b33cd79ae4e5a499cc44c8fc4d8ea27dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yunus=20Dermencio=C4=9Flu?= Date: Fri, 6 Nov 2026 13:31:05 +0300 Subject: [PATCH] Create Emails class for email validation and storage Implement Emails class to validate and store unique email addresses. --- Week05/emails_yunus_dermencioglu.py | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Week05/emails_yunus_dermencioglu.py diff --git a/Week05/emails_yunus_dermencioglu.py b/Week05/emails_yunus_dermencioglu.py new file mode 100644 index 00000000..bc11ef81 --- /dev/null +++ b/Week05/emails_yunus_dermencioglu.py @@ -0,0 +1,32 @@ +import re + + +class Emails(list): + + def __init__(self, emails): + super().__init__() + self.data = [] + + for email in emails: + self.validate(email) + + if email not in self.data: + self.data.append(email) + super().append(email) + + def validate(self, email): + if not isinstance(email, str): + raise ValueError("Email must be a string") + + pattern = r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$" + + if not re.fullmatch(pattern, email): + raise ValueError("Invalid email address") + + return True + + def __repr__(self): + return f"Emails({self.data!r})" + + def __str__(self): + return str(self.data)