Hi everybody,
I leave my solution for this project in the next link:

I hope it is useful for someone else and I await your comments for possible errors or suggestions.
Have a good day!

Nice analysis and documentation! The solution looks correct to me - here are just some suggestions to make the code a bit shorter:

  1. To create a list with N zeros, you used:
[i * 0 for i in range(N)]

Alternatively, you could use:

[0 for i in range(N)]

or, even shorter:

  1. In counting the patients according to region, you apply an if-elif-else statement of the form:
if charge == data[0]:
   cost[0] = ...
elif charge == data[1]:
   cost[1] = ...

Alternatively you could use the .index method of lists to find the index of charge in data and avoid the if-else completely:

idx = data.index(charge)
cost[idx] = ...
  1. The cost by age could also be accomplished with list comprehensions (e.g. for the cost of age 0-25):
cost_under_25 = [c[1] for c in cost_by_age if c[0] < 25]
average_cost_under_25 = sum(cost_under_25) / len(cost_under_25)

Of course, using numpy and pandas would shorten the code even futrher :slight_smile:
Have a nice day!

Thank you so much for your comments. I’m sure that I will use these shorter ways in the future!