From f63dd1cead364e090c634fa21ccbce0ef60e6d8c Mon Sep 17 00:00:00 2001 From: mantuhotep Date: Wed, 7 Jan 2026 18:03:29 +0300 Subject: [PATCH] emails_muhammet_topcu --- Week05/emails_muhammet_topcu.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week05/emails_muhammet_topcu.py diff --git a/Week05/emails_muhammet_topcu.py b/Week05/emails_muhammet_topcu.py new file mode 100644 index 00000000..0fcca786 --- /dev/null +++ b/Week05/emails_muhammet_topcu.py @@ -0,0 +1,26 @@ +import re + +class Emails(list): + def __init__(self, emails): + self.validate(emails) + unique = [] + for e in emails: + if e not in unique: + unique.append(e) + super().__init__(unique) + self.data = unique + + @staticmethod + def validate(emails): + if not all(isinstance(e, str) for e in emails): + raise ValueError("emails must be strings") + pattern = re.compile(r"^[^@]+@[^@]+\.[^@]+$") + for e in emails: + if not pattern.match(e): + raise ValueError("invalid email") + + def __repr__(self): + return f"{self.__class__.__name__}({list(self)})" + + def __str__(self): + return ", ".join(self)