From 721a3c94a0a996ac4162b77e85049929ca848453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elif=20=C3=96ZKANAT?= <154057945+elifozknt@users.noreply.github.com> Date: Sat, 3 Jan 2026 15:55:03 +0300 Subject: [PATCH] Implement Emails class with validation and uniqueness --- Week05/emails_elif_ozkanat.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Week05/emails_elif_ozkanat.py diff --git a/Week05/emails_elif_ozkanat.py b/Week05/emails_elif_ozkanat.py new file mode 100644 index 00000000..4b5d8d13 --- /dev/null +++ b/Week05/emails_elif_ozkanat.py @@ -0,0 +1,28 @@ +import re + + +class Emails(list): + def __init__(self, data): + self.validate(data) + # duplicate'leri kaldır + unique = list(dict.fromkeys(data)) + super().__init__(unique) + self.data = self + + def validate(self, data): + # sadece string olmalı + for item in data: + if not isinstance(item, str): + raise ValueError("All items must be strings") + + # basit ama yeterli email kontrolü + email_pattern = r"^[^@]+@[^@]+\.[^@]+$" + for email in data: + if not re.match(email_pattern, email): + raise ValueError("Invalid email address") + + def __repr__(self): + return f"Emails({list(self)})" + + def __str__(self): + return ", ".join(self)