Write a Python function `dedupe_emails(emails: list[str]) -> list[str]` that removes duplicate email addresses case-insensitively, trims whitespace, skips empty strings, and keeps the first occurrence order. Include a short docstring and 3 example asserts.
SmolLM3 3B
```python
def dedupe_emails(emails: list[str]) -> list[str]:
"""
Removes duplicate email addresses case-insensitively, trims whitespace, skips empty strings,
and keeps the first occurrence order.
Args:
emails (list[str]): A list of email addresses.
Returns:
list[str]: A list of unique email addresses in the original order, with duplicates removed.
"""
seen = set()
result = []
for email in emails:
email = email.strip().lower()
if email and email not in seen:
seen.add(email)
result.append(email)
return [email for email in result if email]
# Example asserts
assert dedupe_emails([" a@b.com", "c@d.com", "a@b.com", " e@f.com", " ", "g@g.com"]) == ["a@b.com", "c@d.com", "e@f.com", "g@g.com"]
assert dedupe_emails([" ", " a@b.com", "c@d.com", "a@b.com", " e@f.com", " ", "g@g.com"]) == ["a@b.com", "c@d.com", "e@f.com", "g@g.com"]
assert dedupe_emails([" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "