From 858406de86404bc43fb61018c9d10ef668b9e9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Feyza=20=C3=96zdemir?= Date: Sat, 31 Oct 2026 14:05:12 +0300 Subject: [PATCH] Add Week05 emails assignment - Feyza --- Week05/emails_feyza_ozdemir.py | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Week05/emails_feyza_ozdemir.py diff --git a/Week05/emails_feyza_ozdemir.py b/Week05/emails_feyza_ozdemir.py new file mode 100644 index 000000000..354d446bd --- /dev/null +++ b/Week05/emails_feyza_ozdemir.py @@ -0,0 +1,49 @@ +class Emails(list): + """ + A custom list class for storing and validating email addresses. + Inherits from the built-in list class. + """ + + def __init__(self, emails_list): + """ + Initializes the Emails object with a list of email addresses. + Validates each email and prevents duplicate entries. + """ + super().__init__() + + self.data = self + + for email in emails_list: + + if not isinstance(email, str): + raise ValueError("All elements must be of type string.") + + if not self.validate(email): + raise ValueError("Invalid email address format.") + + if email not in self: + self.append(email) + + def validate(self, email: str) -> bool: + """ + Validates the email format. + An email is considered valid if it contains an '@' symbol + and a '.' in the domain part (after the '@'). + """ + if "@" in email: + domain_part = email.split("@")[-1] + if "." in domain_part: + return True + return False + + def __repr__(self): + """ + Returns the official string representation of the Emails object. + """ + return super().__repr__() + + def __str__(self): + """ + Returns the user-friendly string representation of the Emails object. + """ + return super().__str__() \ No newline at end of file