From 40365f24f64952d5808f477e64ed468c88af3fce Mon Sep 17 00:00:00 2001 From: 61XeNoN <148587793+61XeNoN@users.noreply.github.com> Date: Wed, 7 Jan 2026 18:07:29 +0300 Subject: [PATCH] emails_abdulsamet_kucuk --- Week05/emails_abdulsamet_kucuk.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week05/emails_abdulsamet_kucuk.py diff --git a/Week05/emails_abdulsamet_kucuk.py b/Week05/emails_abdulsamet_kucuk.py new file mode 100644 index 00000000..0fcca786 --- /dev/null +++ b/Week05/emails_abdulsamet_kucuk.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)