to get sum of the sub lists
Hi there, I tried to perform a code which divide the given list into three. And then get sum of each part into a new list (without build in). For example; given list = [1,2,3,4,5,6,7,8,9] output=[6,15,24] My code: def y(x): Ā Ā Ā t=len(x) Ā Ā Ā z=0 Ā Ā Ā f=0 Ā Ā Ā sum=[] Ā Ā Ā if t%3!=0: Ā Ā Ā Ā Ā Ā Ā return "can not be divided into 3 parts" Ā Ā Ā else: Ā Ā Ā Ā Ā Ā Ā for i in range(z,t,int(t/3)): Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā z=i Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā r=x[z:z+int(t/3)] Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā for j in r: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā f=+j Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā sum.append (f) Ā Ā Ā Ā return sum y([1,2,3,4,5,6]) Ā Ā Ā Ā Ā Ā Ā i could divide the list into three part. However i can not get the true result for sum of each part. Can anyone help me?