From b664fba5447c31a66d3c347198a3f81877ef06a9 Mon Sep 17 00:00:00 2001 From: Kerimcan Dede Date: Fri, 30 Oct 2026 20:33:23 +0300 Subject: [PATCH 1/2] Add Emails class with validation methods --- Week05/emails_kerimcan_dede.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Week05/emails_kerimcan_dede.py diff --git a/Week05/emails_kerimcan_dede.py b/Week05/emails_kerimcan_dede.py new file mode 100644 index 000000000..6e6b6c79a --- /dev/null +++ b/Week05/emails_kerimcan_dede.py @@ -0,0 +1,28 @@ +class Emails(list): + + def validate(self): + for email in self: + if not isinstance(email, str): + raise ValueError("Emails must be string.") + if "@" not in email: + raise ValueError("Emails must contain @.") + if "." not in email.split("@")[1]: + raise ValueError("Emails must contain a dot after @.") + if len(self) != len(set(self)): + raise ValueError("Duplicate emails are not allowed.") + else: + print("Validation is successfull.") + + + def __init__(self, iterable=None): + super().__init__(iterable if iterable is not None else []) + try: + self.validate() + except ValueError as error: + print(error) + + def __repr__(self): + return f"Email list : ({super().__repr__()})" + + def __str__(self): + return f"Email list : {list(self)}" From 68d9e104b93b40a3ffa4afb2d910f5204ba865c4 Mon Sep 17 00:00:00 2001 From: Kerimcan Dede Date: Fri, 30 Oct 2026 20:46:33 +0300 Subject: [PATCH 2/2] Refine email validation and enforce uniqueness Updated email validation to ensure exactly one '@' and added unique email handling. --- Week05/emails_kerimcan_dede.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Week05/emails_kerimcan_dede.py b/Week05/emails_kerimcan_dede.py index 6e6b6c79a..dcaa0f716 100644 --- a/Week05/emails_kerimcan_dede.py +++ b/Week05/emails_kerimcan_dede.py @@ -4,12 +4,10 @@ def validate(self): for email in self: if not isinstance(email, str): raise ValueError("Emails must be string.") - if "@" not in email: - raise ValueError("Emails must contain @.") + if email.count("@") != 1: + raise ValueError("Emails must contain one @.") if "." not in email.split("@")[1]: raise ValueError("Emails must contain a dot after @.") - if len(self) != len(set(self)): - raise ValueError("Duplicate emails are not allowed.") else: print("Validation is successfull.") @@ -21,8 +19,16 @@ def __init__(self, iterable=None): except ValueError as error: print(error) + unique_emails = list(dict.fromkeys(self)) + super().clear() + super().extend(unique_emails) + def __repr__(self): return f"Email list : ({super().__repr__()})" def __str__(self): return f"Email list : {list(self)}" + + @property + def data(self): + return self