PythiloLesson 2 of 8 · progress kept in this browser

Parse CSV without splitting on commas

CSV fields can contain commas, quotes and line breaks. Splitting text manually loses that structure. DictReader understands the format and names fields using the header. Normalize only fields whose rules you know: an email is trimmed and lowercased here, while the supplied display name keeps its internal spaces.

import csv, io
text = "name,email\nAda,a@x.test"
rows = csv.DictReader(io.StringIO(text))
print(next(rows)["name"])
Your task

Write contacts(text). Parse CSV columns name,email; return (trimmed_name, trimmed_lowercase_email) tuples for rows with both values nonempty. Preserve row order and correctly parse quoted commas.