<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_seconds(string):
 """ Converts a human readable time string into seconds. Accepts: - 's': seconds - 'm': minutes - 'h': hours - 'd': days Examples: 90 300 3600 5400 259200 Traceback (most recent call last):
 ValueError """


    units = {
        's': 1,
        'm': 60,
        'h': 60 * 60,
        'd': 60 * 60 * 24
    }

    match = re.search(r'(?:(?P<d>\d+)d)?(?:(?P<h>\d+)h)?(?:(?P<m>\d+)m)?(?:(?P<s>\d+)s)?', string)

    if not match or not any(match.groups()):
        raise ValueError

    total = 0
    for unit, seconds in units.iteritems():
        if match.group(unit) is not None:
            total += int(match.group(unit)) * seconds

    return total