time = '2h' # или
time = '4h 30min' # или
time = '14d'
from functools import reduce
def to_seconds(text):
mult = {
'min': 60,
'h': 60*60,
'd': 24*60*60
}
return reduce(lambda summ, x:summ + int(''.join(filter(str.isdigit, x))) * mult.get(''.join(filter(str.isalpha, x))), text.split(' '), 0)
for im in ['2h', '4h 30min', '14d']:
print(im, to_seconds(im))
# 2h 7200
# 4h 30min 16200
# 14d 1209600