Skip to content

Commit b2f6a5a

Browse files
authored
Add files via upload
1 parent 7f41977 commit b2f6a5a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Week05/emails_ali_duman.py

+28
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)