May-03-2018, 07:43 PM
Hi,
I'd like to know if this is the correct way to approach this kind of problem.
Basically I need to store the sum of every list of L in a new list.
For example: [[1, 2, 3], [5, 6]] => [6, 11]
I'd like to know if this is the correct way to approach this kind of problem.
Basically I need to store the sum of every list of L in a new list.
For example: [[1, 2, 3], [5, 6]] => [6, 11]
#!/usr/bin/python3
L = [[1,2,3],[5,6],[6,7]]
a = []
for i in range(0, len(L)):
sum = 0
for k in L[i]:
sum += k
a.append(sum)
print (a)
