Having such string 12:65:84
and told that it represents time in h:m:s
AND
values there can be not correct, e.g. 65
minutes that should be translated to 1
hour and 5
minutes
I need to reduce these numbers to total amount of seconds.
Naive solution will be:
time_string = '12:65:84'
hours, minutes, seconds = [int(i) for i in time_string.split(':')
total_seconds = hours * 60 * 60 + minutes * 60 + seconds
Question: How it can be done better, ideally without using any import, maybe with some combination of map
, reduce
and their friends?