Skip to content

Commit 76bcac8

Browse files
authored
Create emails_roca_ozdaman.py
1 parent 71f5b39 commit 76bcac8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Week05/emails_roca_ozdaman.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import re
2+
3+
class Emails(list):
4+
def __init__(self, emails):
5+
self.validate(emails)
6+
self.data = list(set(emails))
7+
super().__init__(self.data)
8+
9+
def validate(self, emails):
10+
if not all(isinstance(e, str) for e in emails):
11+
raise ValueError("All items must be strings")
12+
13+
pattern = r"^[^@]+@[^@]+\.[^@]+$"
14+
15+
for email in emails:
16+
if not re.match(pattern, email):
17+
raise ValueError("Invalid email address")
18+
19+
def __repr__(self):
20+
return f"{self.__class__.__name__}({self.data})"
21+
22+
def __str__(self):
23+
return ", ".join(self.data)

0 commit comments

Comments
 (0)