From c78915370804f4ab8e893f2ba12a4abe0d1ff1a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fevzi=20Ba=C4=9Fr=C4=B1a=C3=A7=C4=B1k?= <124450541+fevzibagriacik@users.noreply.github.com> Date: Sat, 20 Dec 2025 16:26:26 +0300 Subject: [PATCH] Create emails_fevzi_bagriacik.py --- Week05/emails_fevzi_bagriacik.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Week05/emails_fevzi_bagriacik.py diff --git a/Week05/emails_fevzi_bagriacik.py b/Week05/emails_fevzi_bagriacik.py new file mode 100644 index 00000000..f355dde9 --- /dev/null +++ b/Week05/emails_fevzi_bagriacik.py @@ -0,0 +1,24 @@ +import re + +class Emails(list): + def __init__(self, data): + self.validate(data) + unique_emails = list(set(data)) + super().__init__(unique_emails) + self.data = unique_emails + + def validate(self, data): + if not all(isinstance(x, str) for x in data): + raise ValueError("All items must be strings") + + pattern = re.compile(r"^[\w\.-]+@[\w\.-]+\.\w+$") + + for email in data: + if not pattern.match(email): + raise ValueError("Invalid email address") + + def __repr__(self): + return f"Emails({list(self)})" + + def __str__(self): + return "\n".join(self)