Codington
0 of 6 problems solved • 0%

Exercise prompt

Read Station Names

Use csv.DictReader(io.StringIO(text)) to iterate over rows as dictionaries. Import both csv and io. The first line supplies the field names.

Example

The header gives each cell a name. Inspect one row whose fields contain punctuation.

import csv from io import StringIO rows = csv.DictReader(StringIO('city,code\n"York, UK",YRK')) first = next(rows) print(first["code"], first["city"]) # YRK York, UK

DictReader keeps the comma inside the quoted city. Looking up the field by name also avoids relying on column order.

Your task

Implement station_names(text). Return the station column from each data row in order. Other columns may appear before it, and some station names contain commas.

station_names('id,station\n1,"Harbor, West"\n') # ["Harbor, West"]