Solution: List of dictionaries



examples/dictionary/list_of_dictionaries.py
import sys

filename = 'examples/csv/monty_python.csv'
if len(sys.argv) == 2:
    filename = sys.argv[1]

people = []

with open(filename) as fh:
    fh.readline()  # skip first row
    for line in fh:
        line = line.rstrip('\n')
        fname, lname, born = line.split(',')
        people.append({
            'fname': fname,
            'lname': lname,
            'born': born,
        })

print(people[1]['fname'])

examples/dictionary/list_of_dictionaries_csv.py
import sys
import csv

filename = 'examples/csv/monty_python.csv'
if len(sys.argv) == 2:
    filename = sys.argv[1]

people = []

with open(filename) as fh:
    reader = csv.DictReader(fh)
    for line in reader:
        people.append(line)

print(people[1]['fname'])