Back to Practice
#0068
Parse Simple CSV Lines
EasyPython18 min15 XP
Problem
Given a list of comma-separated lines where the first line is the header, return a list of dictionaries for the remaining rows. Strip spaces around each cell.
Why This Matters
Reading files often means turning raw text into structured records. This problem practices the core logic without depending on file upload.
Function Signature
def parse_csv_lines(lines):
Examples
Example 1
Input["name,score", "Asha,10", "Ben,8"]
Output[{"name":"Asha","score":"10"}, {"name":"Ben","score":"8"}]
The first line supplies keys for each later row.
Constraints
- No quoted commas are present.
- Return strings, not numeric conversions.
- Handle empty input.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Two records
Input["name,score", "Asha,10", "Ben,8"]
Expectedtwo dictionaries
Header values become dictionary keys.
Hidden Test Categories
empty inputspaces around cellsonly header row