0

My Problem is the following: When creating a dictionary in Jupyter Notebook using Python, the program does not display the full dictionary as per code. Where the dictionary should have len of 1338 (this is the amount of individual lines in my csv doc) it shows me a dictionary with a len of 47. Why is this? I have included my code below.

def create_dict(ages, smoker_statuses, insurance_charges):
    smoker_cost = dict()
    num_patients = len(ages)
    print(num_patients)
    for i in range(num_patients):
        smoker_cost[ages[i]] = {"Age" : ages[i],
                               "Smoker" : smoker_statuses[i],
                               "Charges" : insurance_charges[i]}
    return smoker_cost
print(create_dict(ages, smoker_statuses,insurance_charges))
cost_smoker = create_dict(ages, smoker_statuses,insurance_charges)
print(len(cost_smoker))

Thanks to everyone for their help! Dennis

  • 1
    Please add the code as a code block and not as a screenshot. Please don't post images of code, data, or tracebacks. Copy and paste it as text then format it as code (select it and type ctrl-k). Please [read this](//meta.stackoverflow.com/q/285551) as to why it is discouraged. – Akshay Sehgal Feb 21 '21 at 11:14
  • Does this answer your question? [Dictionary entry overwritten?](https://stackoverflow.com/questions/51313328/dictionary-entry-overwritten) – Nerveless_child Feb 21 '21 at 12:09

0 Answers0