diff --git a/Week05/emails_dilara_agac.py b/Week05/emails_dilara_agac.py new file mode 100644 index 00000000..dd665628 --- /dev/null +++ b/Week05/emails_dilara_agac.py @@ -0,0 +1,23 @@ +import re + + +class Emails(list): + def __init__(self, emails): + self.validate(emails) + super().__init__(list(dict.fromkeys(emails))) + self.data = self + + def validate(self, emails): + if not all(isinstance(e, str) for e in emails): + raise ValueError("All items must be strings") + + email_pattern = re.compile(r"^[^@]+@[^@]+\.[^@]+$") + for email in emails: + if not email_pattern.match(email): + raise ValueError("Invalid email address") + + def __repr__(self): + return f"{self.__class__.__name__}({list(self)})" + + def __str__(self): + return ", ".join(self)