def hex_to_rgb(x):
    """Convert a color hexcode to an rgb tuple.

    Example
    -------
    >>> rgb('#FFFFFF')
    (255, 255, 255)
    """
    if not (x.startswith('#') and len(x) == 7):
        raise ValueError("Invalid hex color")
    x = x.strip('#')
    try:
        return (int(x[:2], 16), int(x[2:4], 16), int(x[4:], 16))
    except ValueError:
        raise ValueError("Invalid hex color")