From b43edf2941d7b30cb3c8f00efb34835472013f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20=C5=9Eamil=20Sar=C4=B1g=C3=BCl?= Date: Tue, 3 Nov 2026 20:14:41 +0300 Subject: [PATCH] Add Emails class for email validation and storage --- Week05/emails_efe_samil_sarigul.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Week05/emails_efe_samil_sarigul.py diff --git a/Week05/emails_efe_samil_sarigul.py b/Week05/emails_efe_samil_sarigul.py new file mode 100644 index 00000000..7ab00149 --- /dev/null +++ b/Week05/emails_efe_samil_sarigul.py @@ -0,0 +1,21 @@ +class Emails(list): + def __init__(self, emails): + self.data = self.validate(emails) + super().__init__(self.data) + + def validate(self, emails): + result = [] + for email in emails: + if type(email) is not str: + raise ValueError("Emails must be strings.") + if email.count("@") != 1 or "." not in email.split("@")[1]: + raise ValueError("Invalid email address.") + if email not in result: + result.append(email) + return result + + def __repr__(self): + return f"Emails({self.data})" + + def __str__(self): + return ", ".join(self.data)