# Conditional sum

I have this data `[income, percentage]`

```
D=[[1300.0, 0.0476],
[1350.0, 0.142],
[1500.0, 0.142],
[1600.0, 0.0476],
[1700.0, 0.0476],
[1800.0, 0.0476],
[1820.0, 0.0476],
[1900.0, 0.0476],
[2000.0, 0.0952],
[2400.0, 0.0952],
[4500.0, 0.0476],
[4900.0, 0.0952],
[5000.0, 0.0952]]
```

I would like to calculate the sum of the incomes conditional to the fact that the cumulative percentages is $\leq 40\%$ and the same thing for $\leq 10\%$ starting from the end of the list.

Of course it's not a too complex task but I would like to know if we can do that inside a conditional sum that is a sum conditionned by an an other. I have something like

```
sum(x[0] for x in D while sum(x[1] for x in D) <= 0.4)
```

which for obvious reasons cannot work.