From 518ed17563155f7e8936bad49bf3a94d001ee81f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Sart=C4=B1k?= Date: Wed, 18 Nov 2026 14:22:05 +0300 Subject: [PATCH] Add Emails class for email validation and storage --- Week05/emails_burak_sartik.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Week05/emails_burak_sartik.py diff --git a/Week05/emails_burak_sartik.py b/Week05/emails_burak_sartik.py new file mode 100644 index 00000000..7ab00149 --- /dev/null +++ b/Week05/emails_burak_sartik.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)