def hexToRgb(hex):
    """
    Converts hex colour codes eg. #FFF or #00FF0F to rgb array

    Args:
      hex (string): colour code # followed by 3 or 6 hexadecimal digits

    Returns:
      Array [r, g, b] each in the range of 0 - 255 inclusive
    """
    # strip '#'
    if hex[0] == "#":
        hex = hex[1:]
    if len(hex) == 3:
        # Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
        return [int(hex[i] * 2, 16) for i in (0, 1, 2)]
    return [int(hex[i : i + 2], 16) for i in (0, 2, 4)]