python 3.5 中的元组操作

tuple operation in python 3.5

我想通过以下方式从给定的元组创建一个新的元组:

1 1

2 3

3 6

4 10

5 15

两个元组应具有相同的维度(元素数)。 可能是这样的:

old_tuple[0] 移动到 new_tuple[0]

new_tuple[0] + old_tuple[1] 移动到 new_tuple[1]

new_tuple[1] + old_tuple[2] 移动到 new_tuple[2]

new_tuple[2] + old_tuple[3] 移动到 new_tuple[3]

new_tuple[3] + old_tuple[4] 移动到 new_tuple[4]

new_tuple[4] + old_tuple[5] 移动到 new_tuple[5]

等等...

终于明白了。将元组更改为列表后,我执行了以下操作:

L2 = [sum(L1[0:n+1]) for n in range(len(L1))]