import numpy as np
from itertools import takewhile
a = [15, 40, 124, 282, 914, 308]
p90 = np.percentile(a, 90)
print(sum(takewhile(lambda x: x < p90, a)))
Cumulative sum of variable till a given percentile