Basically I have the inverse of this problem: Python Time Seconds to h:m:s
I have a string in the format H:MM:SS (always 2 digits for minutes and seconds), and I nee
Without many checks, and assuming it's either "SS" or "MM:SS" or "HH:MM:SS" (although not necessarily two digits per part):
def to_seconds(timestr): seconds= 0 for part in timestr.split(':'): seconds= seconds*60 + int(part) return seconds
This is a different “spelling” of FMc's answer :)