Python U.S. Medical Insurance Costs Portfolio Project zip problem

I am currently doing the US Medical Insurance Cost Portfolio Project and am having trouble combining two lists into a single dictionary. I created two new lists (smoking_status, and insurance_costs) in hope of investigating how insurance costs differ between smokers and non-smokers. When I try to zip these two lists together, however, the new dictionary only has two components. It should have well over a thousand. Where did I go wrong? Below is my code and output.

import csv

insurance_db =

with open(‘insurance.csv’,newline=‘’) as insurance_csv:
insurance_reader = csv.DictReader(insurance_csv)
for row in insurance_reader:
insurance_db.append(row)

smoking_status =

for person in insurance_db:
smoking_status.append(person.get(‘smoker’))

insurance_costs =

for person in insurance_db:
insurance_costs.append(person.get(‘charges’))

smoker_dictionary = {key:value for key,value in zip(smoking_status,insurance_costs)}

print(smoker_dictionary)

{‘yes’: ‘29141.3603’, ‘no’: ‘2007.945’}

Keys in dictionaries must be unique.

ex:


keys = ['steph', 'dray', 'lisa', 'klay', 'jordan', 'otto', 'andre', 'kevon']
values= [1222.55, 1560.00, 1433.88, 7900.01, 7543.25, 13765.22, 3500.24, 2987.57]

new_costs = ((k, v) for k, v in zip(keys, values))
dict(new_costs)

>> {'andre': 3500.24,
 'dray': 1560.0,
 'jordan': 7543.25,
 'kevon': 2987.57,
 'klay': 7900.01,
 'lisa': 1433.88,
 'otto': 13765.22,
 'steph': 1222.55}
1 Like