We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7f41977 commit b2f6a5aCopy full SHA for b2f6a5a
Week05/emails_ali_duman.py
@@ -0,0 +1,28 @@
1
+import re
2
+
3
+class Emails(list):
4
+ def __init__(self, emails):
5
+ validated_emails = self.validate(emails)
6
+ self.data = validated_emails
7
+ super().__init__(validated_emails)
8
9
+ @staticmethod
10
+ def validate(emails):
11
+ unique_emails = []
12
+ email_regex = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
13
14
+ for email in emails:
15
+ if not isinstance(email, str):
16
+ raise ValueError("All items must be strings.")
17
+ if not re.match(email_regex, email):
18
+ raise ValueError(f"Invalid email address: {email}")
19
+ if email not in unique_emails:
20
+ unique_emails.append(email)
21
22
+ return unique_emails
23
24
+ def __repr__(self):
25
+ return f"{self.__class__.__name__}({self.data})"
26
27
+ def __str__(self):
28
+ return f"{self.data}"
0 commit comments