From c801a5629caacf1888f478403e214fed44110c0e Mon Sep 17 00:00:00 2001 From: Emir Karaduman <220315028@ogr.cbu.edu.tr> Date: Thu, 8 Jan 2026 23:07:04 +0300 Subject: [PATCH] emails_emir_karaduman --- Week05/emir_karaduman_emails | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Week05/emir_karaduman_emails diff --git a/Week05/emir_karaduman_emails b/Week05/emir_karaduman_emails new file mode 100644 index 00000000..3d2cc101 --- /dev/null +++ b/Week05/emir_karaduman_emails @@ -0,0 +1,31 @@ +import re + +class Emails(list): + def __init__(self, emails): + self.validate(emails) + + unique = [] + for e in emails: + e = e.strip() + if e not in unique: + unique.append(e) + + super().__init__(unique) + self.data = unique + + @staticmethod + def validate(emails): + if not all(isinstance(e, str) for e in emails): + raise ValueError("All items must be strings") + + pattern = re.compile(r"^[^@]+@[^@]+\.[^@]+$") + + for e in emails: + if not pattern.match(e.strip()): + raise ValueError("Invalid email address") + + def __repr__(self): + return f"Emails({list(self.data)!r})" + + def __str__(self): + return ", ".join(self.data)