<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def housecode_to_index(housecode):
 """Convert a X10 housecode to a zero-based index"""

    match = re.search(r'^([A-P])(\d{1,2})$', housecode.upper())
    if match:
        house_index = int(match.group(2))
        if 1 <= house_index <= 16:
            return (ord(match.group(1)) - ord('A')) * 16 + house_index - 1
    raise ValueError("Invalid X10 housecode: %s" % housecode)