We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 71f5b39 commit 40365f2Copy full SHA for 40365f2
1 file changed
Week05/emails_abdulsamet_kucuk.py
@@ -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
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