From e4026d2a9660105261f4615e75ffe779996351dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleyna=20G=C3=BCltekin?= Date: Wed, 28 Oct 2026 14:47:24 +0300 Subject: [PATCH 1/2] Add Emails class for validating unique email addresses --- Week05/emails_aleyna_gultekin | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Week05/emails_aleyna_gultekin diff --git a/Week05/emails_aleyna_gultekin b/Week05/emails_aleyna_gultekin new file mode 100644 index 000000000..427cc8929 --- /dev/null +++ b/Week05/emails_aleyna_gultekin @@ -0,0 +1,30 @@ +import re + + +class Emails(list): + """A list of unique and valid e-mail addresses.""" + + EMAIL_PATTERN = re.compile(r"^[\w.+-]+@[\w-]+(\.[\w-]+)+$") + + def __init__(self, emails): + valid_emails = self.validate(emails) + super().__init__(valid_emails) + self.data = list(self) + + @staticmethod + def validate(emails): + unique = [] + for email in emails: + if not isinstance(email, str): + raise ValueError(f"{email!r} is not a string") + if not Emails.EMAIL_PATTERN.match(email): + raise ValueError(f"{email!r} is not a valid e-mail address") + if email not in unique: + unique.append(email) + return unique + + def __repr__(self): + return f"Emails({list(self)!r})" + + def __str__(self): + return ", ".join(self) From 238941fc48f25a5555a9ec3df0876bcec12c51ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleyna=20G=C3=BCltekin?= Date: Wed, 28 Oct 2026 14:49:36 +0300 Subject: [PATCH 2/2] Rename emails_aleyna_gultekin to emails_aleyna_gultekin.py --- Week05/{emails_aleyna_gultekin => emails_aleyna_gultekin.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Week05/{emails_aleyna_gultekin => emails_aleyna_gultekin.py} (100%) diff --git a/Week05/emails_aleyna_gultekin b/Week05/emails_aleyna_gultekin.py similarity index 100% rename from Week05/emails_aleyna_gultekin rename to Week05/emails_aleyna_gultekin.py