Beginner
Redact emails and phone numbers
Write redact(text) that replaces every email address with [EMAIL] and every phone number of the form +1 555 010 4477 (a plus, one digit, then groups of 3, 3 and 4 digits separated by spaces) with [PHONE], and returns the new text.
Use the re module with these two patterns: [A-Za-z0-9._-]+@[A-Za-z0-9-]+[.][A-Za-z]{2,} for emails and [+][0-9] [0-9]{3} [0-9]{3} [0-9]{4} for phones. The values in the checks are invented.
What Check tests
- Replaces an email and a phone number
- Replaces every email, not just the first
- Leaves text without personal data unchanged
- Handles a dot before the at sign
- Does not redact an ordinary number
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.