You can use itertools.accumulate from itertools import accumulate l = [1, 2, 3, 4, 5] print([*accumulate(l)]). Prints: [1, 3, 6, 10, 15].
確定! 回上一頁