# this is the list I have:

``````emissions=[30,50,20,70]
``````

# this is the list I would like to get:

``````f=[0,30,30,80,80,100,100,160)

such as:
f=[]
f=emissions
f=emissions
f=emissions+emissions
f=emissions+emissions
f=emissions+emissions+emissions
f=emissions+emissions+emissions
f=emissions+emissions+emissions+emissions
``````

I believe the answer must consider some loop but I cant figure out how

### >Solution :

Use `numpy.cumsum` with append `0`, `numpy.repeat` with remove first and last repetead values by indexing if performance is important in large lists:

``````f = np.repeat(np.cumsum( + emissions), 2)[1:-1].tolist()
print (f)
[0, 30, 30, 80, 80, 100, 100, 170]
``````

``````np.random.seed(123)
emissions = np.random.randint(100, size=1000)

#Timeless solution
In : %%timeit
...: cumsum =  + list(accumulate(emissions))
...: f = [x for pair in zip(cumsum, cumsum[1:]) for x in pair]
...:
242 µs ± 21.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

In : %%timeit
...: np.repeat(np.cumsum( + emissions), 2)[1:-1].tolist()
...:
60.3 µs ± 1.73 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
``````