From 5f4f4bc32425c62bb0be3e15c846d44837a2969e Mon Sep 17 00:00:00 2001 From: Burakcan Aksoy <147622289+burakcnaksy0@users.noreply.github.com> Date: Thu, 8 Jan 2026 05:25:48 +0300 Subject: [PATCH] Create email_burakcan_aksoy.py --- Week05/email_burakcan_aksoy.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Week05/email_burakcan_aksoy.py diff --git a/Week05/email_burakcan_aksoy.py b/Week05/email_burakcan_aksoy.py new file mode 100644 index 00000000..51100026 --- /dev/null +++ b/Week05/email_burakcan_aksoy.py @@ -0,0 +1,32 @@ +import re + +class Emails(list): + EMAIL_REGEX = re.compile(r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$") + + def __init__(self, items): + self._check(items) + cleaned = self._unique(items) + super().__init__(cleaned) + self.data = cleaned + + def _check(self, items): + if not all(type(x) is str for x in items): + raise ValueError("All items must be strings") + + for mail in items: + if not self.EMAIL_REGEX.fullmatch(mail): + raise ValueError("Invalid email address") + + @staticmethod + def _unique(items): + seen = [] + for x in items: + if x not in seen: + seen.append(x) + return seen + + def __repr__(self): + return f"{self.__class__.__name__}({list(self)})" + + def __str__(self): + return "\n".join(self)