From ea49dcbd693cfbfef4ab1837eb8d36b5600afc98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20Altunba=C4=9F?= Date: Wed, 18 Nov 2026 19:16:07 +0300 Subject: [PATCH] Add Week05 homework --- Week05/emails_berkay_altunbag.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Week05/emails_berkay_altunbag.py diff --git a/Week05/emails_berkay_altunbag.py b/Week05/emails_berkay_altunbag.py new file mode 100644 index 00000000..7515ad28 --- /dev/null +++ b/Week05/emails_berkay_altunbag.py @@ -0,0 +1,25 @@ +import re + + +class Emails(list): + """A list of unique, validated email addresses.""" + + _pattern = re.compile(r"^[\w.+-]+@[\w-]+(\.[\w-]+)+$") + + def __init__(self, emails): + self.validate(emails) + self.data = list(dict.fromkeys(emails)) + super().__init__(self.data) + + def validate(self, emails): + for email in emails: + if not isinstance(email, str): + raise ValueError(f"{email!r} is not a string") + if not self._pattern.match(email): + raise ValueError(f"{email!r} is not a valid email address") + + def __repr__(self): + return f"Emails({self.data!r})" + + def __str__(self): + return ", ".join(self.data) \ No newline at end of file