I’ve been trying to complete task 12 from the medical project for Python lists. I’m struggling with how to subtract the estimated cost from the actual cost. I tried using a looping method but that did not seem to work. How can I calculate the difference between these lists? what about using other operators on lists in general?

I’m not sure completely how to fix this, but it seems that when you’re doing the subtraction you’re using two list variables. It might be better to implement a loop which calls in the numerical value of each list and subtracts it, and then you could store the difference in another list.

Have you been able to solve this?

I agree with the previous post;

it would be easier to use a loop to subtract for each element of the list(s).

Note that both the lists `insurance_data`

and `estimated_insurance_data`

are lists of tuples in the form `(name, cost)`

```
differences = []
for (actual_tuple, estimated_tuple) in zip(insurance_data, estimated_insurance_data):
# each tuple is in the form (name, cost) so the cost would be `_tuple[1]` for each tuple
differences.append( actual_tuple[1] - estimated_tuple[1] )
print(differences)
```

2 Likes