Use csv.DictReader when a CSV file has a header row and each record should be accessed as a dictionary. It takes the first row as keys, avoiding the manual combination of next, zip, and dict. section 11.2.2 section 11.6
Read task records as dictionaries
with open("tasks.txt", newline="") as file: csv_reader = csv.DictReader(file) for row in csv_reader: print(row) # {'task_id': '1001', 'title': 'Homework', 'urgency': '5'} # {'task_id': '1002', 'title': 'Laundry', 'urgency': '3'} # {'task_id': '1003', 'title': 'Grocery', 'urgency': '4'} Each iteration produces a dictionary whose keys come from the header: task_id, title, and urgency. The values remain strings in the displayed output. section 11.2.2
task_id,title,urgency 1001,Homework,5 1002,Laundry,3 1003,Grocery,4
Use this sample CSV to see how the header fields become dictionary keys for each task row. section 11.2.2
Prefer this pattern when:
- The CSV includes a header and the field names should remain attached to their values. section 11.2.2
- The file should close automatically after reading; open it with a with statement. section 11.6
- All records are needed at once; convert the iterator with list(csv_reader). section 11.2.2

