File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ class Emails (list ):
2+ def __init__ (self , emails ):
3+ unique_emails = []
4+ seen = set ()
5+ for email in emails :
6+ if email not in seen :
7+ unique_emails .append (email )
8+ seen .add (email )
9+
10+ self .validate (unique_emails )
11+ super ().__init__ (unique_emails )
12+ self .data = self
13+
14+ def validate (self , emails ):
15+ for email in emails :
16+ if not isinstance (email , str ):
17+ raise ValueError ("All items must be strings" )
18+
19+ if "@" not in email :
20+ raise ValueError ("Email must contain @" )
21+
22+ parts = email .split ("@" )
23+ if len (parts ) != 2 or "." not in parts [1 ]:
24+ raise ValueError ("Invalid domain format" )
25+
26+ def __repr__ (self ):
27+ return f"Emails({ super ().__repr__ ()} )"
28+
29+ def __str__ (self ):
30+ return super ().__str__ ()
You can’t perform that action at this time.
0 commit comments