我想通过以下方式从给定元组创建一个新元组:
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]
等等......答案 0 :(得分:0)
最后我明白了。在我将元组更改为列表后,我执行了以下操作:
L2 = [sum(L1[0:n+1]) for n in range(len(L1))]