Skip to content

Commit b43edf2

Browse files
authored
Add Emails class for email validation and storage
1 parent 2024d08 commit b43edf2

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎Week05/emails_efe_samil_sarigul.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Emails(list):
2+
def __init__(self, emails):
3+
self.data = self.validate(emails)
4+
super().__init__(self.data)
5+
6+
def validate(self, emails):
7+
result = []
8+
for email in emails:
9+
if type(email) is not str:
10+
raise ValueError("Emails must be strings.")
11+
if email.count("@") != 1 or "." not in email.split("@")[1]:
12+
raise ValueError("Invalid email address.")
13+
if email not in result:
14+
result.append(email)
15+
return result
16+
17+
def __repr__(self):
18+
return f"Emails({self.data})"
19+
20+
def __str__(self):
21+
return ", ".join(self.data)

0 commit comments

Comments
 (0)