easy +8 pts

Mask email address

Convert an email address into a partially masked string.

Write a function `mask_email(email: str) -> str` that takes a well-formed email address (exactly one '@', no spaces) and returns a masked version. To mask: 1. Split the email into `local` (before `@`) and `domain` (after `@`). 2. If the length of `local` is 1, keep that single character. If it's 2, keep the first and last character unchanged. If it's 3 or more, keep the first character, then a mask of `'*'` repeated (length of local - 2), then the last character. 3. Append the `'@'` and the domain unchanged. For example: `mask_email("alice@example.com")` → `"a***e@example.com"`. You may assume the input is always a valid email address: non-empty, exactly one '@', and no spaces.

Constraints

Input length: 5 to 100 characters. No uppercase letters? Actually uppercase may appear; keep them as-is. Time complexity O(len(email)), space O(len(email)).

Example

>>> mask_email("alice@example.com")
'a***e@example.com'
>>> mask_email("ab@example.com")
'ab@example.com'
>>> mask_email("a@example.com")
'a@example.com'
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `email.split('@')` to separate the local part and domain.
Build the mask part with `'*' * (len(local)-2)`.
Remember to handle lengths 1 and 2 specially.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.