[Python] How to find the cumulative sum of numbers in a list?

Discussão em 'Python' iniciado por Stack, Fevereiro 5, 2025.

  1. Stack

    Stack Membro Participativo

    time_interval = [4, 6, 12]


    I want to sum up the numbers like [4, 4+6, 4+6+12] in order to get the list t = [4, 10, 22].

    I tried the following:

    t1 = time_interval[0]
    t2 = time_interval[1] + t1
    t3 = time_interval[2] + t2
    print(t1, t2, t3) # -> 4 10 22

    Continue reading...

Compartilhe esta Página