Skip to content

Commit 49e500f

Browse files
authored
Create emails_zeynepnur_erten.py
1 parent b536459 commit 49e500f

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎Week05/emails_zeynepnur_erten.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Emails(list):
2+
def __init__(self, emails_list):
3+
checked_emails = self.validate(emails_list)
4+
super().__init__(checked_emails)
5+
self.data=checked_emails
6+
7+
8+
def validate(self,emails_list):
9+
validated_emails = []
10+
for email in emails_list:
11+
if not isinstance(email, str):
12+
raise ValueError('emails must be a string')
13+
if "@" not in email or "." not in email:
14+
raise ValueError('emails must start with @ and must end with .')
15+
if email not in validated_emails:
16+
validated_emails.append(email)
17+
return validated_emails
18+
19+
def __repr__(self):
20+
return f"Emails( {str(list(self))} )"
21+
def __str__(self):
22+
result = "Emails: \n"
23+
for i in self.data:
24+
result += f"{i} \n"
25+
return result

0 commit comments

Comments
 (0)