Fix the email dedup for case-sensitive local parts

Review the AI's codeEasy10 minAnthropic and OpenAI style

Your task

Your service deduplicates user records by email. The first version lowercased whole addresses, which merged Bob@x.com and bob@x.com. A downstream system treats those as two users, because it compares the part before the domain with case. The rewrite folds only the domain.

An assistant wrote dedup_user_emails(emails). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • emails: the addresses, in the order the records arrived. An address may contain more than one @: a quoted local part like "x@y"@mail.com is legal.
  • Return the kept addresses.

Rules the tests check:

  • Split each address at its last @. The part before is the local part, the part after is the domain.
  • Two addresses belong to the same user when their local parts are equal exactly, case included, and their domains are equal ignoring case.
  • An address with no @ matches only the exact same string.
  • Keep the first address of each user, unchanged, in input order.

Examples

dedup_user_emails(emails: list[str]) -> list[str]
Example 1
Inputdedup_user_emails(["Bob@Example.com", "bob@example.com", "Bob@example.COM"])
Output["Bob@Example.com", "bob@example.com"]
Example 2
Inputdedup_user_emails([])
Output[]
Example 3
Inputdedup_user_emails(["a@b.com"])
Output["a@b.com"]