+ 1
List problem
I want to make a new list which add old list's ith elements for example : old list = [1,2,3] , new list will be = [1,3,6]
5 ответов
+ 4
from itertools import accumulate
new_list = list(accumulate(old_list))
+ 4
May be the code is more as i dont know much python . I hope u can understand this code.
l=[1,2,3]
m=[]
s=[]
for i in range(len(l)):
for j in range(i+1):
s.append(l[j])
m.append(sum(s))
s.clear()
print(m)
+ 2
Aakash Gupta, have you actually tried my method?
Because it does exactly what you say.
+ 1
If u have any doubts u can ask