Skip to content

Commit c801a56

Browse files
emails_emir_karaduman
1 parent 71f5b39 commit c801a56

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Week05/emir_karaduman_emails

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

0 commit comments

Comments
 (0)