Skip to content

Commit ffc89c7

Browse files
Create emails_egehan_hatipoglu.py
1 parent b60efee commit ffc89c7

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎Week05/emails_egehan_hatipoglu.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Emails(list):
2+
3+
def __init__(self, initial_emails=None):
4+
super().__init__()
5+
self.data = self
6+
if initial_emails is not None:
7+
self.validate(initial_emails)
8+
9+
def validate(self, emails_to_check):
10+
11+
for item in emails_to_check:
12+
if not isinstance(item, str):
13+
raise ValueError("List can only contain strings")
14+
15+
if "@" not in item:
16+
raise ValueError("Invalid email format")
17+
18+
domain_part = item.split("@")[1]
19+
if "." not in domain_part:
20+
raise ValueError("Invalid email format")
21+
22+
if item not in self:
23+
self.append(item)
24+
25+
def __repr__(self):
26+
return f"Emails({super().__repr__()})"
27+
28+
def __str__(self):
29+
return super().__str__()

0 commit comments

Comments
 (0)