You need to apply 2 fixes to make them work:
- use
iinstead i[2]in the loop linefor - initialize
fbefore loop:
Corresponding part of the code with the applied corrections:
f=0
for i in a:
c=(i[2]//1)*60
d=(i[2]-(i[2]//1))*100
e=c+d
f=f+e
To sum the time in your case, you can use timedeltas:
from datetime import timedelta
import math
a=[("a","b", 3.10),
("c","d", 3.20),
("e","f", 3.30)]
s = timedelta()
for item in a:
seconds, minutes = math.modf(item[2])
s += timedelta(minutes=minutes, seconds=seconds*100)
print s.seconds / 60
source
share