Skip to content

Commit 40365f2

Browse files
authored
emails_abdulsamet_kucuk
1 parent 71f5b39 commit 40365f2

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Week05/emails_abdulsamet_kucuk.py

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

0 commit comments

Comments
 (0)