Label the First Record

Python for AIEasy+10 XP+10

Label the First Record

A pet-adoption site shows the first animal in its file as a featured card. Each line of the card pairs a column name with that animal's value.

Task: write first_record(path, text). It returns a list of strings, one per column, in column order. Each string is "<column name>: <value>" for the first data row. If the file has no data rows, return [].

The starter code includes a small helper, write_text, and already calls it for you: it saves text into a file named path. Your code then opens that file and reads it. import csv is already at the top of the starter code. Use csv.reader and next() to take the column names off first.

Examples

path = 'pets.csv'
text = 'name,kind,age\nrex,dog,3\ntom,cat,5\n'
returns ['name: rex', 'kind: dog', 'age: 3']
path = 'pets2.csv'
text = 'name,home\nkiwi,"Leeds, UK"\n'
returns ['name: kiwi', 'home: Leeds, UK']

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run