I have a large list, an excerpt of which looks like:
power = [
['1234-43211', [5, 6, -4, 11, 22]],
['1234-783411', [43, -5, 0, 0, -1]],
['1234-537611', [3, 0, -5, -6, 0]],
['1567-345411', [4, 6, 8, 3, 3]],
['1567-998711', [1, 2, 1, -4, 5]]
]
The first number in the string is the important one, and the one in which I hope to separate my additions. i.e. I only want to add cumulatively the values within each station (and return each singular cumulative addition), never add the values from two different ones.
My goal is to iterate over this list and add cumulatively the int values for a station, return each addition, then start again when the next station is detected in the list.
Desired result:
new = [
[48, 1, -4, 11, -21],
[ 51, 1, -9, 5, -21], '### End of '1234' ### '
[5, 8, 9, -1, 8], '### End of 1567 ###'
] or something similar to this
I have tried the following:
for i in range(len(power)-1):
front_num_1 = power[i][0].split('-')[0]
front_num_2 = power[i+1][0].split('-')[0]
station = '%s' % (front_num_1)
j = power[i][1]
k = power[i+1][1]
if front_num_1 == front_num_2:
print [k + j for k, j in zip(j, k)]
elif front_num_1 != front_num_2:
print '#####################################
else:
print 'END'
However this addition is not cumulative hence no use.