Drill

ProblemsPython › text

Hide most of an email address

easytextPython

A support screen shows enough of the address for an agent to recognise it, without putting the whole thing on screen.

mask_email(address: string) → string

Solve it in the editor →

Where you start

def mask_email(address: str) -> str:
    

Worked examples

CallResult
mask_email("ahmet@example.com")"a****@example.com"
mask_email("a@b.com")"a@b.com"
mask_email("noatsign")"noatsign"
mask_email("@x.com")"@x.com"

Hint

Find the @ first. Everything follows from where it is.

Reference solution in Python
def mask_email(address: str) -> str:
    at = address.find('@')
    if at <= 0:
        return address
    return address[0] + '*' * (at - 1) + address[at:]

The same problem in another language

More text problems in Python