[Solved] How do i sum consecutively the 4th element of a list of lists (python) [closed]


It is not clear whether or not you need *** around the initial value of 3. If these were a failed attempt to bold the numbers, and you need the number in string format, then try:

cumsum = 0
for i in lst:
    cumsum += int(i[3])
    i[3] = str(cumsum)

>>> lst
[['Lisboa', 36.751510873830824, 204.31859739607566, '3'],
 ['Madrid', 520.8624708804804, 392.9722807116641, '5'],
 ['Copenhaga', 1971.3230985689115, 2086.416520356296, '10'],
 ['Berlin', 2046.6589661942558, 1735.7426148990855, '14']]

2

solved How do i sum consecutively the 4th element of a list of lists (python) [closed]