(duration_str)
return seconds
Acceptable formats are: "MM:SS", "HH:MM" and "HH:MM:SS".
Acceptable formats are: "MM:SS", "HH:MM" and "HH:MM:SS".
Acceptable formats are : MM : SS HH : MM and HH : MM : SS .
def duration_to_seconds(duration_str):
    """
    Acceptable formats are: "MM:SS", "HH:MM" and "HH:MM:SS".
    """
    values = duration_str.split(':')
    
    if len(values) == 1:
        raise Exception('Invalid value supplied: %s', duration_str)
    
    seconds = 0
    
    for i, val in enumerate(reversed(values)):        
        val = int(val) * pow(60, i)
        seconds = seconds + val
        
    return seconds
def duration_to_seconds ( duration_str ) : values = duration_str . split ( ':' ) if len ( values ) == 1 : raise Exception ( 'Invalid value supplied: %s' , duration_str ) seconds = 0 for i , val in enumerate ( reversed ( values ) ) : val = int ( val ) * pow ( 60 , i ) seconds = seconds + val return seconds