Skip to content

Commit 68d9e10

Browse files
authored
Refine email validation and enforce uniqueness
Updated email validation to ensure exactly one '@' and added unique email handling.
1 parent b664fba commit 68d9e10

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎Week05/emails_kerimcan_dede.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ def validate(self):
44
for email in self:
55
if not isinstance(email, str):
66
raise ValueError("Emails must be string.")
7-
if "@" not in email:
8-
raise ValueError("Emails must contain @.")
7+
if email.count("@") != 1:
8+
raise ValueError("Emails must contain one @.")
99
if "." not in email.split("@")[1]:
1010
raise ValueError("Emails must contain a dot after @.")
11-
if len(self) != len(set(self)):
12-
raise ValueError("Duplicate emails are not allowed.")
1311
else:
1412
print("Validation is successfull.")
1513

@@ -21,8 +19,16 @@ def __init__(self, iterable=None):
2119
except ValueError as error:
2220
print(error)
2321

22+
unique_emails = list(dict.fromkeys(self))
23+
super().clear()
24+
super().extend(unique_emails)
25+
2426
def __repr__(self):
2527
return f"Email list : ({super().__repr__()})"
2628

2729
def __str__(self):
2830
return f"Email list : {list(self)}"
31+
32+
@property
33+
def data(self):
34+
return self

0 commit comments

Comments
 (0)