Essential storage keeps sign-in and learning features working. Google Analytics measures visits; Microsoft Clarity records interactions to help us improve usability. Both are optional and stay off until you choose. Read our privacy policy.
Normalize an email address coding exercise | SovranCode
Pythonbeginner 18 min
CODING EXERCISE
Normalize an email address
Return a normalized email address by trimming surrounding whitespace and lower-casing its local and domain parts. Reject strings without exactly one @ and non-string input with None.
Requirements
Return None for invalid input
Trim before splitting
Do not invent provider-specific rules
Example
Input
Ada.Lovelace@Example.COM
Expected output
ada.lovelace@example.com
Show a hint
Write down the input contract and the failure cases before coding.
tests
Loads Python in an isolated browser worker, then runs your function
RUNTIME OUTPUT
Ready to run the file open above against 1 test.
LEARN FROM THE SOLUTION
Why the solution works.
The function validates the small contract it owns rather than attempting a full email deliverability check. Counting @ before unpacking turns malformed input into a predictable None result instead of an exception.
What this exercise teaches
Strings
Validation
Tuple unpacking
A PRACTICAL PLAN
Work through Normalize an email address with intent.
Translate the contract.Turn the requirements into a short checklist before editing your-solution.py.
Use the example as evidence.Predict the result for the supplied input, then add one boundary case such as an empty value, a limit, or unexpected input.
Review the implementation.Compare your choices against solution.py only after a real attempt.
EXERCISE FAQ
Before you move on.
What does “Normalize an email address” teach?
This beginner Python exercise focuses on Strings, Validation, Tuple unpacking. Its requirements define the exact behavior to implement before you write code.
How should I validate this Python solution?
Start with the displayed example input and expected output, then test a boundary case suggested by the requirements. Open your-solution.py and select Run code. The browser loads Python in an isolated worker and runs your function against the visible tests.
When should I open the reference solution?
Attempt Normalize an email address first. Then open the read-only solution file to compare the contract, edge-case handling, and implementation choices—not simply to copy the final code.