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